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.
* 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>
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>
* cc: tzanke@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/25520#comment:3>
* cc: jernej@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/25520#comment:4>
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>
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>
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>
* status: new => closed
* resolution: => duplicate
--
Ticket URL: <https://code.djangoproject.com/ticket/25520#comment:8>