From 88b230f0e446bc21deb27465d6f0167763081564 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Mon, 30 Aug 2021 16:55:31 -0400 Subject: [PATCH] Fixes #7071: Fix exception when removing a primary IP from a device/VM --- docs/release-notes/version-3.0.md | 1 + netbox/ipam/models/ip.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/version-3.0.md b/docs/release-notes/version-3.0.md index e8b9e1963..fd7603c0e 100644 --- a/docs/release-notes/version-3.0.md +++ b/docs/release-notes/version-3.0.md @@ -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 --- diff --git a/netbox/ipam/models/ip.py b/netbox/ipam/models/ip.py index 6c1b2d439..3e2e671ca 100644 --- a/netbox/ipam/models/ip.py +++ b/netbox/ipam/models/ip.py @@ -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!"