#26195: order_by pk doesn't work in multi-table inheritance models if parent has
default ordering
-------------------------------------+-------------------------------------
Reporter: ris | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: multi table | Triage Stage:
inheritance order_by MTI pk | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):
* status: new => closed
* resolution: => wontfix
Comment:
While it might not be intuitive `ModelB.objects.order_by('pk')` is
equivalent to `ModelB.objects.order_by('modela_ptr')` which will use the
`ordering` defined on `ModelA` as
[https://docs.djangoproject.com/en/1.9/ref/models/querysets/#order-by
documented].
Note that before #19195 was fixed it was not even possible to bypass the
order by related model's ordering behavior.
At this point I'm afraid we'll have to stick to the actual behavior and
keep requiring an explicit order by `id` because of the backward
incompatibilities such a change would introduce.
If we wanted to special case `order_by('pk')` to prevent the usage of the
referenced model ordering it would have to go through a deprecation period
where a warning is raised if `pk` is a field pointing to a model with a
defined `ordering` option.
In short I'm -0 on introducing such a change as it will require a
deprecation period and will introduce yet another edge case in the
handling of `ordering` by the ORM in order to expose a non-intuitive
behavior to users familar with the actual `ordering` behavior.
I will close the ticket as ''wontfix'' but feel free to post to the
developer's mailing list to gather support for such a change.
--
Ticket URL: <https://code.djangoproject.com/ticket/26195#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/061.80ebb7009bdd83be126440e701ea7a4d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.