From e0f14d83898ee7d0d3180eb96214d8fcdf82cc1d Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Wed, 7 Sep 2022 22:30:06 -0400 Subject: [4.1.x] Fixed #33992 -- Fixed queryset crash when aggregating over a group containing Exists. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A more in-depth solution is likely to make sure that we always GROUP BY selected annotations or revisit how we use Query.exists() in the Exists expression but that requires extra work that isn't suitable for a backport. Regression in e5a92d400acb4ca6a8e1375d1ab8121f2c7220be. Thanks Fernando Flores Villaça for the report. Backport of 32536b1324e98768dd892980408a8c6b26c23fd9 from main --- tests/aggregation/tests.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/aggregation') diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index c6d73e8042..bbd4620710 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -1663,6 +1663,17 @@ class AggregateTestCase(TestCase): ).values_list("publisher_count", flat=True) self.assertSequenceEqual(books_breakdown, [1] * 6) + def test_aggregation_exists_multivalued_outeref(self): + self.assertCountEqual( + Publisher.objects.annotate( + books_exists=Exists( + Book.objects.filter(publisher=OuterRef("book__publisher")) + ), + books_count=Count("book"), + ), + Publisher.objects.all(), + ) + def test_filter_in_subquery_or_aggregation(self): """ Filtering against an aggregate requires the usage of the HAVING clause. -- cgit v1.3