1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #28900 -- Propagated all selected fields to combinator queries.

Previously, only the selected column aliases would be propagated and
annotations were ignored.
This commit is contained in:
Simon Charette
2023-03-30 01:23:12 -04:00
committed by Sarah Boyce
parent 65ad4ade74
commit 6d220963fa
3 changed files with 14 additions and 13 deletions

View File

@@ -1375,6 +1375,16 @@ class Queries1Tests(TestCase):
self.assertCountEqual(items_after, [self.i2, self.i3, self.i4])
self.assertCountEqual(items_before, items_after)
def test_union_values_subquery(self):
items = Item.objects.filter(creator=OuterRef("pk"))
item_authors = Author.objects.annotate(is_creator=Exists(items)).order_by()
reports = Report.objects.filter(creator=OuterRef("pk"))
report_authors = Author.objects.annotate(is_creator=Exists(reports)).order_by()
all_authors = item_authors.union(report_authors).order_by("is_creator")
self.assertEqual(
list(all_authors.values_list("is_creator", flat=True)), [False, True]
)
class Queries2Tests(TestCase):
@classmethod