[Django] #25520: Cascade delete of proxy model children fails with IntegrityErrors

6 views
Skip to first unread message

Django

unread,
Oct 6, 2015, 8:47:33 PM10/6/15
to django-...@googlegroups.com
#25520: Cascade delete of proxy model children fails with IntegrityErrors
-------------------------------+--------------------
Reporter: jmurty | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
When deleting a concrete model based on proxy models, Django's deletion
collector does not find M2M reverse relationships to proxy parents; it
only finds these relationships for concrete parent models.

This means that deleting a proxy-based model object with extant M2M
relationships targeting a proxy parent will fail with integrity errors if
you use a database like PostgreSQL that enforces foreign key constraints.
The target model instance cannot be deleted because the M2M FK
relationships are not also deleted at the same time, and would otherwise
remain pointing to a non-existent record.

This issue tends to affect users of django-polymorphic who rely more than
most on proxy models, and has been reported in this context in #23076

I have created a Pull Requests based on the current master branch that
adds unit tests demonstrating the issue when run against a database that
enforces foreign key constrains, such as PostgreSQL:
https://github.com/django/django/pull/5404

This issue also affects versions 1.7 and 1.8 and perhaps also earlier
versions, but likely has not been encountered broadly because the use case
that triggers it is somewhat unusual.

--
Ticket URL: <https://code.djangoproject.com/ticket/25520>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 6, 2015, 8:48:24 PM10/6/15
to django-...@googlegroups.com
#25520: Cascade delete of proxy model children fails with IntegrityErrors
-------------------------------------+-------------------------------------
Reporter: jmurty | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(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 jmurty):

* cc: james@… (added)
* needs_better_patch: => 0
* component: Uncategorized => Database layer (models, ORM)
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => Bug


--
Ticket URL: <https://code.djangoproject.com/ticket/25520#comment:1>

Django

unread,
Oct 6, 2015, 8:56:00 PM10/6/15
to django-...@googlegroups.com
#25520: Cascade delete of proxy model children fails with IntegrityErrors
-------------------------------------+-------------------------------------
Reporter: jmurty | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: master
(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 jmurty):

Per a comment by akaariai on #23076:

This might be related to #25505 and #18012.

--
Ticket URL: <https://code.djangoproject.com/ticket/25520#comment:2>

Django

unread,
Oct 7, 2015, 2:28:46 AM10/7/15
to django-...@googlegroups.com
#25520: Cascade delete of proxy model children fails with IntegrityErrors
-------------------------------------+-------------------------------------
Reporter: jmurty | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: master
(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 TZanke):

* cc: tzanke@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/25520#comment:3>

Django

unread,
Oct 7, 2015, 5:11:35 AM10/7/15
to django-...@googlegroups.com
#25520: Cascade delete of proxy model children fails with IntegrityErrors
-------------------------------------+-------------------------------------
Reporter: jmurty | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: master
(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 kostko):

* cc: jernej@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/25520#comment:4>

Django

unread,
Oct 7, 2015, 6:53:05 AM10/7/15
to django-...@googlegroups.com
#25520: Cascade delete of proxy model children fails with IntegrityErrors
-------------------------------------+-------------------------------------
Reporter: jmurty | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: master
(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 jmurty):

The linked pull request now includes a patch to fix this issue for
deletion:
https://github.com/ixc/django/commit/47aa8c6ec276965eccfe3a52694109d8258562de

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

Django

unread,
Oct 7, 2015, 10:39:44 AM10/7/15
to django-...@googlegroups.com
#25520: Cascade delete of proxy model children fails with IntegrityErrors
-------------------------------------+-------------------------------------
Reporter: jmurty | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: master
(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 charettes):

This is really just a symptom of the issue described in #23076 and #25505
and should be closed as a duplicate.

IMO the correct fix would be to propagate reverse foreign keys from proxy
models to their concrete base (#18012) and then simply make sure the proxy
model deletion code always retrieve the reverse relationships from
concrete models.

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

Django

unread,
Oct 7, 2015, 6:33:33 PM10/7/15
to django-...@googlegroups.com
#25520: Cascade delete of proxy model children fails with IntegrityErrors
-------------------------------------+-------------------------------------
Reporter: jmurty | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: master
(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 jmurty):

FWIW the [https://github.com/django/django/pull/5378 PR proposed fix for
#18012] looks reasonable to me: propagating the reverse FKs of proxy
models to their base seems to match assumptions made in the code for
deletion. However I am not familiar enough with the code and issues to
properly understand any implications or trade-offs, so I won't weigh in
over there.

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

Django

unread,
Oct 9, 2015, 2:31:45 PM10/9/15
to django-...@googlegroups.com
#25520: Cascade delete of proxy model children fails with IntegrityErrors
-------------------------------------+-------------------------------------
Reporter: jmurty | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: duplicate
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):

* status: new => closed
* resolution: => duplicate


--
Ticket URL: <https://code.djangoproject.com/ticket/25520#comment:8>

Reply all
Reply to author
Forward
0 new messages