summaryrefslogtreecommitdiff
path: root/tests/queries
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2023-03-30 01:23:12 -0400
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-07-03 16:36:25 +0200
commit6d220963fa275a8431fcbcc05de1468f9f8bc3d3 (patch)
tree1cb52cca46cd0e7deaf2ebe918b0324f8cbd0a6e /tests/queries
parent65ad4ade74dc9208b9d686a451cd6045df0c9c3a (diff)
Fixed #28900 -- Propagated all selected fields to combinator queries.
Previously, only the selected column aliases would be propagated and annotations were ignored.
Diffstat (limited to 'tests/queries')
-rw-r--r--tests/queries/test_qs_combinators.py6
-rw-r--r--tests/queries/tests.py10
2 files changed, 11 insertions, 5 deletions
diff --git a/tests/queries/test_qs_combinators.py b/tests/queries/test_qs_combinators.py
index e130613084..eac1533803 100644
--- a/tests/queries/test_qs_combinators.py
+++ b/tests/queries/test_qs_combinators.py
@@ -282,11 +282,7 @@ class QuerySetSetOperationTests(TestCase):
)
.values_list("num", "count")
)
- qs2 = (
- Number.objects.filter(num=2)
- .extra(select={"count": 1})
- .values_list("num", "count")
- )
+ qs2 = Number.objects.filter(num=2).extra(select={"count": 1})
self.assertCountEqual(qs1.union(qs2), [(1, 0), (2, 1)])
def test_union_with_values_list_on_annotated_and_unannotated(self):
diff --git a/tests/queries/tests.py b/tests/queries/tests.py
index 3621b6cb2c..ec88fa558d 100644
--- a/tests/queries/tests.py
+++ b/tests/queries/tests.py
@@ -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