1. Use a database that supports `can_defer_constraint_checks` (tested on
postgres)
1. Have a model (A) with a `null=True` ForeignKey or OneToOneField (F) to
another model (B)
1. Connect a function to listen to `post_delete` on (B) that pulls
objects of type (A) from the db (using a = A.objects.get... etc )
1. Try to access a.F for an object a that used to be associated with the
deleted instance of B that was just deleted
Expectation: a.F_id is `None`
Actually: a.F_id is the id of the deleted instance and a.F raises an
ObjectDoesNotExist exception
Note: doesn't repro on fields where `null=False` or on sqlite. My
diagnosis is that A's field isn't being properly cleared (or A objects
deleted in the case of on delete CASCADE) because the constraint checks
aren't being flushed until _after_ the `post_delete` signal fires
--
Ticket URL: <https://code.djangoproject.com/ticket/26630>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Only tried on CASCADE deletes, I think it blames to this code -
https://github.com/django/django/blob/master/django/db/models/deletion.py#L15
--
Ticket URL: <https://code.djangoproject.com/ticket/26630#comment:1>
Comment (by timgraham):
If you could provide a test case for Django's test suite, that would be
helpful.
--
Ticket URL: <https://code.djangoproject.com/ticket/26630#comment:2>
* Attachment "t26630.tar.gz" added.
sample app to reproduce
* stage: Unreviewed => Accepted
Comment:
Seems legitimate. I attached a sample project I used to reproduce. The
first test method shows the failure.
--
Ticket URL: <https://code.djangoproject.com/ticket/26630#comment:3>
* owner: nobody => Can Sarıgöl
* status: new => assigned
* version: 1.9 => master
Comment:
[https://github.com/django/django/pull/11780 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/26630#comment:4>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/26630#comment:5>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/26630#comment:6>
* owner: Can Sarıgöl => (none)
--
Ticket URL: <https://code.djangoproject.com/ticket/26630#comment:7>