#26434: Inconsistent results of QuerySet.count() when ordering is not a subset
of
explicit grouping.
-------------------------------------+-------------------------------------
Reporter: kamandol | Owner: Michal
| Mládek
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: postgresql queryset | Triage Stage: Accepted
count annotate aggreagate |
order_by |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):
* summary:
Inconsistent results of QuerySet count() method using PostgreSQL
backend prior and post the QuerySet evaluation
=>
Inconsistent results of QuerySet.count() when ordering is not a subset
of explicit grouping.
Comment:
FWIW the issue is not Postgres specific (I reproduced against SQLite).
The problem appears to be caused by `sql.Query.get_aggregation`'s call to
`clear_ordering(force=False)`. It seems like the later should skip
clearing when `isinstance(self.group_by, tuple)` and `self.order_by` is
not a subset of `self.group_by` as `force=False` must only clear if doing
to preserves the semantic of the query which it doesn't if `order_by`
includes members missing from the group by (as they would normally be
added).
I adjusted the ticket summary accordingly.
--
Ticket URL: <https://code.djangoproject.com/ticket/26434#comment:15>
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 visit
https://groups.google.com/d/msgid/django-updates/01070196d8387674-7441b4d6-cf96-4883-855d-7ed99c40911e-000000%40eu-central-1.amazonses.com.