From 93748907249922f9e066d991dcbe0c310728603d Mon Sep 17 00:00:00 2001 From: Daniel Sheppard Date: Thu, 21 Dec 2023 14:25:14 -0600 Subject: [PATCH] Fix test failure --- netbox/ipam/forms/model_forms.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/netbox/ipam/forms/model_forms.py b/netbox/ipam/forms/model_forms.py index 5acd6707a..f1b165838 100644 --- a/netbox/ipam/forms/model_forms.py +++ b/netbox/ipam/forms/model_forms.py @@ -370,9 +370,12 @@ class IPAddressForm(TenancyForm, NetBoxModelForm): ) prev_interface = self.instance.interface.first() or self.instance.vminterface.first() - prev_parent = prev_interface.device or prev_interface.virtual_machine - if prev_interface and prev_parent and prev_interface != interface: - if prev_parent.primary_ip4 == self.instance or prev_parent.primary_ip6 == self.instance: + # If the prev interface exists and does not match the new interface, we need to validate it isn't set as primary + # for the parent + if prev_interface and prev_interface != interface: + prev_parent = prev_interface.device or prev_interface.virtual_machine + # Check that the parent exists and if it is set as a primary ip. + if prev_parent and prev_parent.primary_ip4 == self.instance or prev_parent.primary_ip6 == self.instance: self.add_error( selected_objects[0], _("Cannot reassign IP address while it is designated as the primary IP for the parent object")