#28395: first() adds id field to group by clause on aggregation queries
--------------------------------------+------------------------------------
Reporter: John Gresty | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master
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 Simon Charette):
* component: Database layer (models, ORM) => Documentation
* version: 1.11 => master
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted
Comment:
The `first()` method requires an ordering to be specified else it would
return non-deterministic results hence why it's using `order_by('pk')`
when the queryset isn't ordered.
This is a bit similar to #10574 except the implicit ordering is added by
`first()` and not `_meta.ordering` so I'd suggest
[https://docs.djangoproject.com/en/1.11/topics/db/aggregation
/#interaction-with-default-ordering-or-order-by we link to the aggregation
section mentioning interaction with default ordering] or adjust the
documention to account for that.
IMHO it would have been better for `first()` to raise an exception when
called on an unordered queryset instead of implicitly choosing `pk` but in
your case I assume you want to either `order_by('group')` or `'value'`
before calling `first()`.
--
Ticket URL: <https://code.djangoproject.com/ticket/28395#comment:1>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.9f2b8e0acb328eb19ae32edb30f4eeb9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.