From 0d08205ab13c9eb9fb18ba8546764ce7af26f9fc Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 21 Dec 2023 16:20:13 -0500 Subject: [PATCH] Fixes #14532: Device/VM change record should accurately reflect when primary/OOB IP is deleted --- netbox/ipam/signals.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/netbox/ipam/signals.py b/netbox/ipam/signals.py index 2a985c294..3b36b561f 100644 --- a/netbox/ipam/signals.py +++ b/netbox/ipam/signals.py @@ -56,8 +56,12 @@ def clear_primary_ip(instance, **kwargs): """ field_name = f'primary_ip{instance.family}' if device := Device.objects.filter(**{field_name: instance}).first(): + device.snapshot() + setattr(device, field_name, None) device.save() if virtualmachine := VirtualMachine.objects.filter(**{field_name: instance}).first(): + virtualmachine.snapshot() + setattr(virtualmachine, field_name, None) virtualmachine.save() @@ -67,4 +71,6 @@ def clear_oob_ip(instance, **kwargs): When an IPAddress is deleted, trigger save() on any Devices for which it was a OOB IP. """ if device := Device.objects.filter(oob_ip=instance).first(): + device.snapshot() + device.oob_ip = None device.save()