﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28781	Order of queryset.union() with queryset.values() is incorrect	Amir Aziiev	nobody	"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);
------------^
""""""
}}}
"	Bug	new	Database layer (models, ORM)	1.11	Normal		union, values		Unreviewed	0	0	0	0	0	0
