#28781: Order of queryset.union() with queryset.values() is incorrect
-------------------------------------+-------------------------------------
               Reporter:  Amir       |          Owner:  nobody
  Aziiev                             |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  1.11
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:  union, values
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 For example:

 {{{
 from django.db import models


 class Mymodel(models.Model):
     col1 = models.CharField(max_length=11)
     col2 = models.CharField(max_length=22)
     col3 = models.CharField(max_length=33)


 qs = MyModel.objects.union(MyModel.objects.all(), all=True).values('col2',
 'col3', 'col1', 'id').order_by('col1')
 print(qs.query)
 # Expected SQL
 """
 (SELECT "mymodel"."id", "mymodel"."col1", "mymodel"."col2",
 "mymodel"."col3" FROM "mymodel")
   UNION ALL
 (SELECT"mymodel"." id", "mymodel"."col1", "mymodel"."col2",
 "mymodel"."col3" FROM "mymodel")
   ORDER BY (3);
 ------------^
 """
 # Must be SQL
 """
 (SELECT "mymodel"."id", "mymodel"."col1", "mymodel"."col2",
 "mymodel"."col3" FROM "mymodel")
   UNION ALL
 (SELECT"mymodel"." id", "mymodel"."col1", "mymodel"."col2",
 "mymodel"."col3" FROM "mymodel")
   ORDER BY (2);
 ------------^
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28781>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.27ab2eeb79601ec8a51dafc0e32476ad%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to