[Django] #26630: Defered constraint checks flush after `post_delete` signal

14 views
Skip to first unread message

Django

unread,
May 18, 2016, 12:31:46 AM5/18/16
to django-...@googlegroups.com
#26630: Defered constraint checks flush after `post_delete` signal
----------------------------------------------+--------------------
Reporter: alexmadjar | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
Repro steps:

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.

Django

unread,
May 18, 2016, 12:36:50 AM5/18/16
to django-...@googlegroups.com
#26630: Defered constraint checks flush after `post_delete` signal
-------------------------------------+-------------------------------------

Reporter: alexmadjar | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by alexmadjar):

* 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>

Django

unread,
May 18, 2016, 11:26:14 AM5/18/16
to django-...@googlegroups.com
#26630: Defered constraint checks flush after `post_delete` signal
-------------------------------------+-------------------------------------

Reporter: alexmadjar | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
May 28, 2016, 5:59:38 PM5/28/16
to django-...@googlegroups.com
#26630: Defered constraint checks flush after `post_delete` signal
-------------------------------------+-------------------------------------

Reporter: alexmadjar | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* Attachment "t26630.tar.gz" added.

sample app to reproduce

Django

unread,
May 28, 2016, 6:00:30 PM5/28/16
to django-...@googlegroups.com
#26630: Defered constraint checks flush after `post_delete` signal
-------------------------------------+-------------------------------------

Reporter: alexmadjar | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* 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>

Django

unread,
Sep 13, 2019, 10:38:11 AM9/13/19
to django-...@googlegroups.com
#26630: Defered constraint checks flush after `post_delete` signal
-------------------------------------+-------------------------------------
Reporter: Alex Madjar | Owner: Can
| Sarıgöl
Type: Bug | Status: assigned
Component: Database layer | Version: master

(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Can Sarıgöl):

* 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>

Django

unread,
Sep 13, 2019, 11:25:58 AM9/13/19
to django-...@googlegroups.com
#26630: Defered constraint checks flush after `post_delete` signal
-------------------------------------+-------------------------------------
Reporter: Alex Madjar | Owner: Can
| Sarıgöl
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Can Sarıgöl):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/26630#comment:5>

Django

unread,
Oct 4, 2019, 9:31:45 AM10/4/19
to django-...@googlegroups.com
#26630: Defered constraint checks flush after `post_delete` signal
-------------------------------------+-------------------------------------
Reporter: Alex Madjar | Owner: Can
| Sarıgöl
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/26630#comment:6>

Django

unread,
Apr 12, 2023, 5:09:35 PM4/12/23
to django-...@googlegroups.com
#26630: Defered constraint checks flush after `post_delete` signal
-------------------------------------+-------------------------------------
Reporter: Alex Madjar | Owner: (none)
Type: Bug | Status: assigned
Component: Database layer | Version: dev

(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Can Sarıgöl):

* owner: Can Sarıgöl => (none)


--
Ticket URL: <https://code.djangoproject.com/ticket/26630#comment:7>

Reply all
Reply to author
Forward
0 new messages