[Django] #25505: Incomplete relation_tree for inherited proxied Models.

6 views
Skip to first unread message

Django

unread,
Oct 5, 2015, 11:55:29 AM10/5/15
to django-...@googlegroups.com
#25505: Incomplete relation_tree for inherited proxied Models.
-------------------------------------+-------------------------------------
Reporter: jelko | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) | Keywords: models, meta, deletion,
Severity: Normal | relation, inheritance
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
`Options._populate_directed_relation_graph` produces an incomplete
`Options._relation_tree` for Models that have set `Meta.Proxy = True`.

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.

Django

unread,
Oct 5, 2015, 11:56:02 AM10/5/15
to django-...@googlegroups.com
#25505: Incomplete relation_tree for inherited proxied Models.
-------------------------------------------------+-------------------------

Reporter: jelko | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.8
Severity: Normal | Resolution:
Keywords: models, meta, deletion, relation, | Triage Stage:
inheritance | Unreviewed

Has patch: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------------+-------------------------
Changes (by jelko):

* Attachment "models.py" added.

Django

unread,
Oct 5, 2015, 12:41:09 PM10/5/15
to django-...@googlegroups.com
#25505: Incomplete relation_tree for inherited proxied Models.
-------------------------------------+-------------------------------------
Reporter: jelko | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: models, meta, | Triage Stage:
deletion, relation, inheritance | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

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

Django

unread,
Oct 5, 2015, 1:29:37 PM10/5/15
to django-...@googlegroups.com
#25505: Incomplete relation_tree for inherited proxied Models.
-------------------------------------+-------------------------------------
Reporter: jelko | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: models, meta, | Triage Stage: Accepted
deletion, relation, inheritance |

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

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

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

Django

unread,
Oct 5, 2015, 1:30:01 PM10/5/15
to django-...@googlegroups.com
#25505: Incomplete relation_tree for inherited proxied Models.
-------------------------------------+-------------------------------------
Reporter: jelko | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: models, meta, | Triage Stage: Accepted
deletion, relation, inheritance |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* Attachment "25505-reproduced-issue.diff" added.

Integrated test case

Django

unread,
Oct 5, 2015, 1:37:04 PM10/5/15
to django-...@googlegroups.com
#25505: Incomplete relation_tree for inherited proxied Models.
-------------------------------------+-------------------------------------
Reporter: jelko | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: models, meta, | Triage Stage: Accepted
deletion, relation, inheritance |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

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>

Django

unread,
Oct 6, 2015, 12:08:20 AM10/6/15
to django-...@googlegroups.com
#25505: Incomplete relation_tree for inherited proxied Models.
-------------------------------------+-------------------------------------
Reporter: jelko | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: models, meta, | Triage Stage: Accepted
deletion, relation, inheritance |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by charettes):

This looks related to #23076.

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

Django

unread,
Oct 12, 2015, 12:35:18 PM10/12/15
to django-...@googlegroups.com
#25505: Incomplete relation_tree for inherited proxied Models.
-------------------------------------+-------------------------------------
Reporter: jelko | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: models, meta, | Triage Stage: Accepted
deletion, relation, inheritance |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette <charette.s@…>):

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

Reply all
Reply to author
Forward
0 new messages