#14357: Prevent inappropriate order-based grouping on values+annotate queries
-------------------------------------+-------------------------------------
Reporter: Martin Chase | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version:
(models, ORM) |
Severity: Normal | Resolution:
Keywords: 3.1 | Triage Stage:
| Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by nE0sIghT):
* status: closed => new
* resolution: fixed =>
Comment:
I beleave this was not properly fixed in commit 0ddb4ebf.
While commit 0ddb4ebf removes `ORDER BY` when Meta.ordering is used it
still does populates `GROUP BY` with Meta.ordering fields thus leads to
wrong aggregation.
Look to get_group_by() at compiler.py [1] - it populates `GROUP BY` using
previously obtained order_by with `Meta.ordering` fields [2][3].
For what I see we must filter off `Meta.ordering` fields from order_by in
get_group_by() function.
[1]
https://github.com/django/django/blob/3.1.7/django/db/models/sql/compiler.py#L128
[2]
https://github.com/django/django/blob/3.1.7/django/db/models/sql/compiler.py#L56
[3]
https://github.com/django/django/blob/3.1.7/django/db/models/sql/compiler.py#L286
--
Ticket URL: <https://code.djangoproject.com/ticket/14357#comment:23>
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/070.555278bccc6f326d90c5f58e8f39648d%40djangoproject.com.