[Django] #36686: Update documentation on 'never removes' ordering.

2 views
Skip to first unread message

Django

unread,
Oct 24, 2025, 10:54:20 AM10/24/25
to django-...@googlegroups.com
#36686: Update documentation on 'never removes' ordering.
-----------------------+-----------------------------------------
Reporter: wutje | Type: Bug
Status: new | Component: Documentation
Version: 5.2 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------+-----------------------------------------
Today I hunted an ordering bug. I have a model with {{{ordering =
['name']}}}

And in a view I use:
{{{queryset.annotate(used_by=Count('somerelation'))}}} which drops the
order_by.

However the documentation for a aggregation states:
https://docs.djangoproject.com/en/5.2/topics/db/aggregation/ that:
{{{Django never removes ordering constraints that you have specified}}}.

But then I saw the changelog for version. 2.2. Which explicitly states:

{{{A model’s Meta.ordering affecting GROUP BY queries (such as
.annotate().values()) is a common source of confusion. Such queries now
issue a deprecation warning with the advice to add an order_by() to retain
the current query. Meta.ordering will be ignored in such queries starting
in Django 3.1.}}}

Where do I find this information in the current documentation? I think
this information is currently missing.
--
Ticket URL: <https://code.djangoproject.com/ticket/36686>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 24, 2025, 5:15:54 PM10/24/25
to django-...@googlegroups.com
#36686: Update documentation on 'never removes' ordering.
-------------------------------+------------------------------------
Reporter: Wouter | Owner: (none)
Type: Bug | Status: new
Component: Documentation | Version: 5.2
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 Jacob Walls):

* stage: Unreviewed => Accepted

Comment:

The [https://docs.djangoproject.com/en/5.2/topics/db/aggregation
/#interaction-with-order-by current documentation only discusses] the
effect of performing a `GROUP BY` query after a queryset with
`.order_by()`, but I agree that from this you cannot deduce the effect of
doing the same on a model with `Meta.ordering`, which you might assume
acts the same (especially given the "Django never..." wording you quote).

Clarifying that note would be welcome. Would you like to submit a PR?
--
Ticket URL: <https://code.djangoproject.com/ticket/36686#comment:1>
Reply all
Reply to author
Forward
0 new messages