From 10037130c123cd747d32a14a9ba47e0c5c9a37d1 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Sun, 13 Nov 2022 23:45:33 -0500 Subject: Refs #28477 -- Fixed handling aliased annotations on aggregation. Just like when using .annotate(), the .alias() method will generate the necessary JOINs to resolve the alias even if not selected. Since these JOINs could be multi-valued non-selected aggregates must be considered to require subquery wrapping as a GROUP BY is required to combine duplicated tuples from the base table. Regression in 59bea9efd2768102fc9d3aedda469502c218e9b7. --- django/db/models/sql/query.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'django/db/models/sql') diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 775e2668b0..c858816289 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -443,7 +443,7 @@ class Query(BaseExpression): return {} existing_annotations = { alias: annotation - for alias, annotation in self.annotation_select.items() + for alias, annotation in self.annotations.items() if alias not in added_aggregate_names } # Existing usage of aggregation can be determined by the presence of -- cgit v1.3