From 277eea8fcced7f04f3800617f189beb349a3212e Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Tue, 23 Feb 2021 20:56:29 -0500 Subject: 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. --- tests/aggregation/tests.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') 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('?') -- cgit v1.3