#35309: Remove Order by on models when prefetching by id
-------------------------------------+-------------------------------------
Reporter: Laurent Lyaudet | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: prefetch order_by | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
Please refrain from assuming bad faith from triagers regarding the
resolution of this ticket. The provided resolution was a reflected based
on your report details and in no way based on your persona.
What do you suggest should happen for the thousands of projects out there
that rely on `prefetch_related` to return results in a way that respects
`Meta.ordering`? We can't simply make the behaviour of `prefetch_related`
inconsistent with the normal behaviour or related manager access because
it performs poorly when defined against an non-indexed field. I think the
documentation warning I referred to is unfortunately all we can do to warn
about this behaviour. Either use `Meta.ordering` and be prepared to deal
with its implicit footguns or don't use it and use `order_by` where
appropriate.
Whether `Meta.ordering` should exist in the first place is debatable as
it's at the origin of many unexpected behaviour with other features of the
ORM (aggregation comes to mind) but making `prefetch_related` special case
it would not only be backward incompatible but inconsistent with how the
rest of the framework treats it.
--
Ticket URL: <https://code.djangoproject.com/ticket/35309#comment:4>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018e45219a8c-4cf523eb-82b6-49f8-828a-923a60e82a0b-000000%40eu-central-1.amazonses.com.