#28553: Querysets: annotate() columns are forced into a certain position which
may
disrupt union()
-------------------------------------+-------------------------------------
Reporter: David Sanders | Owner: David
| Wobrock
Type: Bug | Status: closed
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):
* cc: Simon Charette (added)
Comment:
Small note that the cases reported in comment:3 is not fixed, the merged
patch only focuses on the case where only annotations are referenced in
`values`/`values_list` which is a subset of the problem reported here as
mixing field references, extra, and annotations demonstrate.
The crux of the issue is that `SQLCompiler.get_select` ignores
`Query.values_select` and
[https://github.com/django/django/blob/cffcf0ef17b2dfd744d3bc64080229c1b500508f/django/db/models/sql/compiler.py#L247-L276
always generate selected columns as follow]
1. Start with `Query.extra_select`
2. Then `Query.select`
3. End with `Query.annotation_select`
The patch here only makes sure that the order of `annotation_select` is
preserved. What should be done instead is adjust `get_select` to be
`Query.values_select` aware as pointed out on the MR.
--
Ticket URL: <https://code.djangoproject.com/ticket/28553#comment:12>
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/0107018715121612-a0b29299-83ca-4550-9d59-09749d21f7be-000000%40eu-central-1.amazonses.com.