diff options
| author | Simon Charette <charette.s@gmail.com> | 2021-02-23 20:56:29 -0500 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-02-24 10:11:37 +0100 |
| commit | 7a6ca01f4eb990772080e2978f19d83484184b04 (patch) | |
| tree | 7d55d49a62a679c6544e3db2c2987eced9f1f37f /tests/aggregation | |
| parent | 543171873f0565b93b3ad603fe72f92468d012a4 (diff) | |
[3.2.x] 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.
Backport of 277eea8fcced7f04f3800617f189beb349a3212e from master
Diffstat (limited to 'tests/aggregation')
| -rw-r--r-- | tests/aggregation/tests.py | 15 |
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('?') |
