From 7530cf3900ab98104edcde69e8a2a415e82b345a Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Fri, 17 Nov 2023 19:42:44 -0500 Subject: 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. --- 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 a073d01590..af6c660cf1 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -2309,3 +2309,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