mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #31496 -- Fixed QuerySet.values()/values_list() crash on combined querysets ordered by annotations.
This commit is contained in:
parent
300def5c34
commit
464a4c0c59
3 changed files with 41 additions and 10 deletions
|
@ -211,6 +211,28 @@ class QuerySetSetOperationTests(TestCase):
|
|||
with self.subTest(qs=qs):
|
||||
self.assertEqual(list(qs), expected_result)
|
||||
|
||||
def test_union_with_values_list_and_order_on_annotation(self):
|
||||
qs1 = Number.objects.annotate(
|
||||
annotation=Value(-1),
|
||||
multiplier=F('annotation'),
|
||||
).filter(num__gte=6)
|
||||
qs2 = Number.objects.annotate(
|
||||
annotation=Value(2),
|
||||
multiplier=F('annotation'),
|
||||
).filter(num__lte=5)
|
||||
self.assertSequenceEqual(
|
||||
qs1.union(qs2).order_by('annotation', 'num').values_list('num', flat=True),
|
||||
[6, 7, 8, 9, 0, 1, 2, 3, 4, 5],
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
qs1.union(qs2).order_by(
|
||||
F('annotation') * F('multiplier'),
|
||||
'num',
|
||||
).values('num'),
|
||||
[6, 7, 8, 9, 0, 1, 2, 3, 4, 5],
|
||||
operator.itemgetter('num'),
|
||||
)
|
||||
|
||||
def test_count_union(self):
|
||||
qs1 = Number.objects.filter(num__lte=1).values('num')
|
||||
qs2 = Number.objects.filter(num__gte=2, num__lte=3).values('num')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue