diff options
Diffstat (limited to 'django/db/models/sql/query.py')
| -rw-r--r-- | django/db/models/sql/query.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index ac735012f1..220ae92754 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -498,6 +498,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 |
