#34771: order_by on annotated field that's not present in values/values_list 
causes
SQL syntax error
-------------------------------------+-------------------------------------
     Reporter:  Yitao Xiong          |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  3.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  mysql                |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Yitao Xiong):

 Oh, an interesting discovery I just found when doing more experiments.

 This doesn't seem to be an issue that applies to all fields. For instance,
 I just found out that the same pattern worked for `IntegerField`:

 {{{
 In [20]: User.objects.annotate(random_stuff=Value(1,
 output_field=IntegerField())).order_by('random_stuff').values('id')
 Out[20]: <QuerySet [{'id': 1}, {'id': 2}, '...(remaining elements
 truncated)...']>
 }}}

 So I'm guess it's something specific with MySQL, given your example also
 showed the boolean query worked in Postgres.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34771#comment:5>
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/01070189e5b78690-4e3f7359-6d93-4772-b238-29e6fb21fbaa-000000%40eu-central-1.amazonses.com.

Reply via email to