From 720de4d0441fcfdb543051389c70efbe66ed962a Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Sat, 21 Dec 2019 23:22:49 -0500 Subject: Fixed #31109 -- Disabled grouping by aliases on QuerySet.exists(). Clearing the SELECT clause in Query.has_results was orphaning GROUP BY references to it. Thanks Thierry Bastian for the report and Baptiste Mispelon for the bisect. Regression in fb3f034f1c63160c0ff13c609acd01c18be12f80. --- tests/aggregation/tests.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/aggregation') diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index ecbe81c151..dd30f57bed 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -1141,6 +1141,16 @@ class AggregateTestCase(TestCase): # The GROUP BY should not be by alias either. self.assertEqual(ctx[0]['sql'].lower().count('latest_book_pubdate'), 1) + def test_aggregation_subquery_annotation_exists(self): + latest_book_pubdate_qs = Book.objects.filter( + publisher=OuterRef('pk') + ).order_by('-pubdate').values('pubdate')[:1] + publisher_qs = Publisher.objects.annotate( + latest_book_pubdate=Subquery(latest_book_pubdate_qs), + count=Count('book'), + ) + self.assertTrue(publisher_qs.exists()) + @skipUnlessDBFeature('supports_subqueries_in_group_by') def test_group_by_subquery_annotation(self): """ -- cgit v1.3