#25316: Can't use order_by and values(_list) together after annotating
-------------------------------------+-------------------------------------
     Reporter:  adrian17             |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  1.8
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  annotate, order_by   |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by lucasmoeskops):

 I think this is not an issue.

 The problem is that the example is annotating a field and then sorts on
 this field. To do this, the field needs to exist still in the select. It
 is however thrown away by values, so it can't sort on it.

 The example will work correctly if the annotated field is added to the
 values list as well. It will also work correctly if no order on the
 annotated field is applied.

 If this were to work, the resulting query would be considerably more
 complex, involving a different final select than the select to apply the
 ordering on.

 What could be improved though is the error message. This is clear when no
 annotation is used. Maybe something like "Can't deselect annotated value"
 or "Can't order on unselected annotated field `other`"?

--
Ticket URL: <https://code.djangoproject.com/ticket/25316#comment:3>
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/066.b0467438159c1a7dddef7d3240e6cb23%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to