From 9daf8b4109c3e133eb57349bb44d73cc60c5773c Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Thu, 6 Apr 2023 08:19:53 -0400 Subject: Fixed #34464 -- Fixed queryset aggregation over group by reference. Regression in 59bea9efd2768102fc9d3aedda469502c218e9b7. Refs #28477. Thanks Ian Cubitt for the report. --- django/db/models/sql/query.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'django') diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index ef55dbe3a9..2ffcfaa10c 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -453,6 +453,9 @@ class Query(BaseExpression): # filtering against window functions is involved as it # requires complex realising. annotation_mask = set() + if isinstance(self.group_by, tuple): + for expr in self.group_by: + annotation_mask |= expr.get_refs() for aggregate in aggregates.values(): annotation_mask |= aggregate.get_refs() inner_query.set_annotation_mask(annotation_mask) -- cgit v1.2.1