From c705a49830405c71fe33a6d9e7c465d2b9049a2d Mon Sep 17 00:00:00 2001 From: Brian Tiemann Date: Thu, 24 Apr 2025 11:22:56 -0400 Subject: [PATCH] Only set remote field to None if null=True on the relation --- netbox/core/signals.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/core/signals.py b/netbox/core/signals.py index 6c3cc0fda..0bed3fd45 100644 --- a/netbox/core/signals.py +++ b/netbox/core/signals.py @@ -161,7 +161,7 @@ def handle_deleted_object(sender, instance, **kwargs): obj.snapshot() # Ensure the change record includes the "before" state if type(relation) is ManyToManyRel: getattr(obj, related_field_name).remove(instance) - elif type(relation) is ManyToOneRel: + elif type(relation) is ManyToOneRel and relation.field.null is True: setattr(obj, related_field_name, None) obj.save()