Consider this setup:
BaseModel(models.Model) -> ProxyModel(BaseModel) [with Proxy = True] ->
ChildModel(ProxyModel)
In this case the OneToOne relation from ProxyModel to ChildModel is not
included in the proxymodel's `_meta._relation_tree`.
This is caused because `Options._populate_directed_relation_graph`
collects the relations by calling `model._meta._get_fields(reverse=False,
include_parents=False)`. Therefore the parent, in this case the ProxyModel
is not included.
This results in some unwanted situations. If you call `delete()` on a
ProxyModel, the BaseModel gets deleted, but the ChildModel instance stays
in the database and becomes orphaned.
Have a look at the attached models.py to replicate the setup. Compare the
behavior of `delete()` for instances of `ChipShop` and `IndianRestaurant`,
to see the problem.
--
Ticket URL: <https://code.djangoproject.com/ticket/25505>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "models.py" added.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Hi jelko,
Could have a look at the [https://github.com/django/django/pull/5378
patch] proposed for #18012 and see if that fixes the reported issue. I
haven't tried it myself but from the description you provided it looks
like the same scenario.
--
Ticket URL: <https://code.djangoproject.com/ticket/25505#comment:1>
* cc: charettes (added)
* stage: Unreviewed => Accepted
Comment:
It looks like this is another can of worms.
The patch proposed for #18012 doesn't fix the reported issue which I
managed to reproduce with the attached test case.
--
Ticket URL: <https://code.djangoproject.com/ticket/25505#comment:2>
* Attachment "25505-reproduced-issue.diff" added.
Integrated test case
Comment (by charettes):
Note that the test case uses `exists()` instead of `get()` because the
latter won't return any results and hide the issue because of deferred
constraint checks in the transaction wrapping the test case.
--
Ticket URL: <https://code.djangoproject.com/ticket/25505#comment:3>
Comment (by charettes):
This looks related to #23076.
--
Ticket URL: <https://code.djangoproject.com/ticket/25505#comment:4>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"211486f3ab5602cdc332f03cd03fad3cb929d154" 211486f3]:
{{{
#!CommitTicketReference repository=""
revision="211486f3ab5602cdc332f03cd03fad3cb929d154"
Fixed #23076, #25505 -- Fixed deletion of intermediate proxy models.
Thanks to James Murty for his work on an alternate patch.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25505#comment:5>