Fixes #7071: Fix exception when removing a primary IP from a device/VM

This commit is contained in:
jeremystretch 2021-08-30 16:55:31 -04:00
parent deb53d771d
commit 88b230f0e4
2 changed files with 3 additions and 2 deletions

View File

@ -5,6 +5,7 @@
### Bug Fixes
* [#7070](https://github.com/netbox-community/netbox/issues/7070) - Fix exception when filtering by prefix max length in UI
* [#7071](https://github.com/netbox-community/netbox/issues/7071) - Fix exception when removing a primary IP from a device/VM
---

View File

@ -825,9 +825,9 @@ class IPAddress(PrimaryModel):
if self.pk:
for cls, attr in ((Device, 'device'), (VirtualMachine, 'virtual_machine')):
parent = cls.objects.filter(Q(primary_ip4=self) | Q(primary_ip6=self)).first()
if parent and getattr(self.assigned_object, attr) != parent:
if parent and getattr(self.assigned_object, attr, None) != parent:
# Check for a NAT relationship
if not self.nat_inside or getattr(self.nat_inside.assigned_object, attr) != parent:
if not self.nat_inside or getattr(self.nat_inside.assigned_object, attr, None) != parent:
raise ValidationError({
'interface': f"IP address is primary for {cls._meta.model_name} {parent} but "
f"not assigned to it!"