diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-08-01 16:16:28 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-08-01 16:17:06 +0200 |
| commit | 8808d9da6b11b8aa32d750265217721450b0fb1f (patch) | |
| tree | b5e1a4c6ccd102810256423c31ce6db73d7f44a7 /django/db/models/sql | |
| parent | 2ef2b2ffc0e2af3f945bccf99ece67f843aa440c (diff) | |
[4.2.x] Fixed #34750 -- Fixed QuerySet.count() when grouping by unused multi-valued annotations.
Thanks Toan Vuong for the report.
Thanks Simon Charette for the review.
Regression in 59bea9efd2768102fc9d3aedda469502c218e9b7.
Backport of c9b9a52edc66be117c6e5b5214fa788a4d5db7a8 from main
Diffstat (limited to 'django/db/models/sql')
| -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 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 |
