[Django] #24266: Deprecate `Options.get_parent_list` in favor of a new `get_ancestors` one.

7 views
Skip to first unread message

Django

unread,
Feb 3, 2015, 2:15:07 AM2/3/15
to django-...@googlegroups.com
#24266: Deprecate `Options.get_parent_list` in favor of a new `get_ancestors` one.
-------------------------------------+-------------------------------------
Reporter: charettes | Owner: nobody
Type: | Status: new
Uncategorized |
Component: Database | Version: master
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The `get_parent_list()` method was introduced
[https://github.com/django/django/blame/a53541852d5601232899e54d66e623bc163c6dc2/django/db/models/options.py#L647-L656
more than 6 years ago] and has been returning an unordered `set()` since
then.

From the method name suffix and the misleading `__doc__` I guess the
returned data type was changed late in the process of merging
[https://github.com/django/django/commit/9c52d56f6f8a9cdafb231adf9f4110473099c9b5
Malcom's queryset refactor] in order to deal with the multiple ORM's
ancestors existence checks by reducing
[https://wiki.python.org/moin/TimeComplexity time complexity].

While working on fixing a field shadowing issue in multi-inheritance
scenarios (#24249) it was discovered that
[https://github.com/django/django/pull/4018#issuecomment-72201349
`get_parent_list()` actually returns] an unordered `set()` which might
causes non-deterministic behaviors. For example, another patch working on
making sure unique checks take multi-inheritance into account (#15321)
could result in different validation errors being raised from the same
input based on the non-deterministic ordering of ancestors.

Since the undocumented `get_parent_list()` method seems to be
[https://github.com/search?utf8=%E2%9C%93&q=get_parent_list+language%3Apython&type=Code&ref=searchresults
used in the wild] I suggest we deprecate and replace it by a
`get_ancestors()` one with the following properties:

* A more significant name given it returns ancestors regardless of
lineage.
* A return value ordered by the `__mro__` of the model.
* A return value with `in` operations with similar time complexity.

One of the available data structure with the required return value
properties is `django.utils.datastructures.OrderedSet` but I wonder if the
whole time complexity argument is not moot given multi-inheritance
scenarios involving many ancestors shouldn't be that common.

In this case, given we don't mind about backward compatibility of such a
private API, we could also fix `get_parent_list()` to actually return a
list of unique ancestors ordered by `__mro__`.

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

Django

unread,
Feb 3, 2015, 1:34:24 PM2/3/15
to django-...@googlegroups.com
#24266: Deprecate `Options.get_parent_list` in favor of a new `get_ancestors` one.
-------------------------------------+-------------------------------------
Reporter: charettes | Owner: nobody
Type: | Status: new
Cleanup/optimization |
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 timgraham):

* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted


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

Django

unread,
Feb 3, 2015, 2:50:55 PM2/3/15
to django-...@googlegroups.com
#24266: Change `get_parent_list` to return a list of parents ordered by __mro__
instead of a set

-------------------------------------+-------------------------------------
Reporter: charettes | Owner: nobody
Type: | Status: new
Cleanup/optimization |
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
-------------------------------------+-------------------------------------

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

Django

unread,
Feb 3, 2015, 3:22:38 PM2/3/15
to django-...@googlegroups.com
#24266: Change `get_parent_list` to return a list of parents ordered by __mro__
instead of a set
-------------------------------------+-------------------------------------
Reporter: charettes | Owner: nobody
Type: | Status: new
Cleanup/optimization |
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 charettes):

* has_patch: 0 => 1


Comment:

Created a [https://github.com/django/django/pull/4043 PR].

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

Django

unread,
Feb 3, 2015, 4:12:26 PM2/3/15
to django-...@googlegroups.com
#24266: Change `get_parent_list` to return a list of parents ordered by __mro__
instead of a set
-------------------------------------+-------------------------------------
Reporter: charettes | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Accepted => Ready for checkin


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

Django

unread,
Feb 3, 2015, 4:41:17 PM2/3/15
to django-...@googlegroups.com
#24266: Change `get_parent_list` to return a list of parents ordered by __mro__
instead of a set
-------------------------------------+-------------------------------------
Reporter: charettes | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | 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:"65e005f8cd9c656e558e53e6c8b890cd0fcc9e74"]:
{{{
#!CommitTicketReference repository=""
revision="65e005f8cd9c656e558e53e6c8b890cd0fcc9e74"
Fixed #24266 -- Changed get_parent_list to return a list ordered by MRO.

Thanks to Aron Podrigal for the initial patch and Tim for the review.
}}}

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

Django

unread,
Feb 3, 2015, 4:42:19 PM2/3/15
to django-...@googlegroups.com
#24266: Change `get_parent_list` to return a list of parents ordered by __mro__
instead of a set
-------------------------------------+-------------------------------------
Reporter: charettes | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette <charette.s@…>):

In [changeset:"cbcf92e95f8a6d275b55069de3c57835814b502f"]:
{{{
#!CommitTicketReference repository=""
revision="cbcf92e95f8a6d275b55069de3c57835814b502f"
[1.8.x] Fixed #24266 -- Changed get_parent_list to return a list ordered
by MRO.

Thanks to Aron Podrigal for the initial patch and Tim for the review.

Backport of 65e005f8cd9c656e558e53e6c8b890cd0fcc9e74 from master
}}}

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

Reply all
Reply to author
Forward
0 new messages