diff --git a/netbox/core/signals.py b/netbox/core/signals.py index 2994aaa41..d918d2389 100644 --- a/netbox/core/signals.py +++ b/netbox/core/signals.py @@ -3,7 +3,7 @@ from threading import local from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist, ValidationError -from django.db.models import CASCADE +from django.db.models import CASCADE, RESTRICT from django.db.models.fields.reverse_related import ManyToManyRel, ManyToOneRel from django.db.models.signals import m2m_changed, post_migrate, post_save, pre_delete from django.dispatch import receiver, Signal @@ -221,7 +221,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 and relation.null and relation.on_delete is not CASCADE: + elif type(relation) is ManyToOneRel and relation.null and relation.on_delete not in (CASCADE, RESTRICT): setattr(obj, related_field_name, None) obj.save()