diff --git a/django/db/models/query.py b/django/db/models/query.py index 23d0bac6c8f..4d0d295e975 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -1180,7 +1180,7 @@ def delete_objects(seen_objs): if field.rel and field.null and field.rel.to in seen_objs: setattr(instance, field.attname, None) - setattr(instance, cls._meta.pk.attname, None) dispatcher.send(signal=signals.post_delete, sender=cls, instance=instance) + setattr(instance, cls._meta.pk.attname, None) transaction.commit_unless_managed() diff --git a/tests/modeltests/signals/models.py b/tests/modeltests/signals/models.py index d41142135e2..1fb73828bb5 100644 --- a/tests/modeltests/signals/models.py +++ b/tests/modeltests/signals/models.py @@ -54,7 +54,7 @@ Is updated pre_delete signal, Tom Smith instance.id is not None: True post_delete signal, Tom Smith -instance.id is None: True +instance.id is None: False >>> p2 = Person(first_name='James', last_name='Jones') >>> p2.id = 99999 @@ -73,7 +73,7 @@ Is created pre_delete signal, James Jones instance.id is not None: True post_delete signal, James Jones -instance.id is None: True +instance.id is None: False >>> Person.objects.all() []