mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #29286 -- Fixed column mismatch crash with QuerySet.values() or values_list() after combining an annotated and unannotated queryset with union(), difference(), or intersection().
Regression in a0c03c62a8
.
Thanks Tim Graham and Carlton Gibson for reviews.
This commit is contained in:
parent
e1f13f1551
commit
0b66c3b442
4 changed files with 21 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
|||
from django.db.models import F, IntegerField, Value
|
||||
from django.db.models import Exists, F, IntegerField, OuterRef, Value
|
||||
from django.db.utils import DatabaseError, NotSupportedError
|
||||
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
|
||||
|
||||
|
@ -130,6 +130,14 @@ class QuerySetSetOperationTests(TestCase):
|
|||
).values_list('num', 'count')
|
||||
self.assertCountEqual(qs1.union(qs2), [(1, 0), (2, 1)])
|
||||
|
||||
def test_union_with_values_list_on_annotated_and_unannotated(self):
|
||||
ReservedName.objects.create(name='rn1', order=1)
|
||||
qs1 = Number.objects.annotate(
|
||||
has_reserved_name=Exists(ReservedName.objects.filter(order=OuterRef('num')))
|
||||
).filter(has_reserved_name=True)
|
||||
qs2 = Number.objects.filter(num=9)
|
||||
self.assertCountEqual(qs1.union(qs2).values_list('num', flat=True), [1, 9])
|
||||
|
||||
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