From acf4cee95144c55a12492cdd71fa795d7accfe26 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Fri, 17 Nov 2023 19:42:44 -0500 Subject: [4.2.x] Fixed #34975 -- Fixed crash of conditional aggregate() over aggregations. Adjustments made to solve_lookup_type to defer the resolving of references for summarized aggregates failed to account for similar requirements for lookup values which can also reference annotations through Aggregate.filter. Regression in b181cae2e3697b2e53b5b67ac67e59f3b05a6f0d. Refs #25307. Thanks Sergey Nesterenko for the report. Backport of 7530cf3900ab98104edcde69e8a2a415e82b345a from main --- tests/aggregation/tests.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index 8d8e46e312..48266d9774 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -2300,3 +2300,9 @@ class AggregateAnnotationPruningTests(TestCase): aggregate, {"sum_avg_publisher_pages": 1100.0, "books_count": 2}, ) + + def test_aggregate_reference_lookup_rhs(self): + aggregates = Author.objects.annotate( + max_book_author=Max("book__authors"), + ).aggregate(count=Count("id", filter=Q(id=F("max_book_author")))) + self.assertEqual(aggregates, {"count": 1}) -- cgit v1.3