Opened 3 hours ago
#36686 new Bug
Update documentation on 'never removes' ordering.
| Reported by: | Wouter | Owned by: | |
|---|---|---|---|
| Component: | Documentation | Version: | 5.2 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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.