summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/query.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index c9656cc450..27f94175bb 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -482,6 +482,11 @@ class Query(BaseExpression):
annotation_mask |= expr.get_refs()
for aggregate in aggregates.values():
annotation_mask |= aggregate.get_refs()
+ # Avoid eliding expressions that might have an incidence on
+ # the implicit grouping logic.
+ for annotation_alias, annotation in self.annotation_select.items():
+ if annotation.get_group_by_cols():
+ annotation_mask.add(annotation_alias)
inner_query.set_annotation_mask(annotation_mask)
# Add aggregates to the outer AggregateQuery. This requires making