summaryrefslogtreecommitdiff
path: root/tests/aggregation
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2021-02-23 20:56:29 -0500
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-02-24 09:01:36 +0100
commit277eea8fcced7f04f3800617f189beb349a3212e (patch)
tree95595b6c299ea769cd53068505806d344e82e310 /tests/aggregation
parent3aa545281e0c0f9fac93753e3769df9e0334dbaa (diff)
downloaddjango-277eea8fcced7f04f3800617f189beb349a3212e.tar.gz
Fixed #32478 -- Included nested columns referenced by subqueries in GROUP BY on aggregations.
Regression in fb3f034f1c63160c0ff13c609acd01c18be12f80. Refs #31094, #31150. Thanks Igor Pejic for the report.
Diffstat (limited to 'tests/aggregation')
-rw-r--r--tests/aggregation/tests.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py
index 0bced06ce9..49123396dd 100644
--- a/tests/aggregation/tests.py
+++ b/tests/aggregation/tests.py
@@ -1311,6 +1311,21 @@ class AggregateTestCase(TestCase):
# self.assertSequenceEqual(books_qs, [book])
# self.assertEqual(ctx[0]['sql'].count('SELECT'), 2)
+ @skipUnlessDBFeature('supports_subqueries_in_group_by')
+ def test_aggregation_nested_subquery_outerref(self):
+ publisher_with_same_name = Publisher.objects.filter(
+ id__in=Subquery(
+ Publisher.objects.filter(
+ name=OuterRef(OuterRef('publisher__name')),
+ ).values('id'),
+ ),
+ ).values(publisher_count=Count('id'))[:1]
+ books_breakdown = Book.objects.annotate(
+ publisher_count=Subquery(publisher_with_same_name),
+ authors_count=Count('authors'),
+ ).values_list('publisher_count', flat=True)
+ self.assertSequenceEqual(books_breakdown, [1] * 6)
+
def test_aggregation_random_ordering(self):
"""Random() is not included in the GROUP BY when used for ordering."""
authors = Author.objects.annotate(contact_count=Count('book')).order_by('?')