diff options
| author | Christian Klus <christianklus@gmail.com> | 2020-10-27 13:13:10 -0500 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-10-29 09:56:09 +0100 |
| commit | 4ac2d4fa42e1659f328c35b6b8d4761b3419c11a (patch) | |
| tree | 3c063ae382ae6c77a3e2064ccfa97f62fbd35583 /django/db/models/sql | |
| parent | 9ca22c7733efeeb140b75585c6387ef2cb861d19 (diff) | |
Fixed #32152 -- Fixed grouping by subquery aliases.
Regression in 42c08ee46539ef44f8658ebb1cbefb408e0d03fe.
Thanks Simon Charette for the review.
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/query.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index abb545eaa4..d34b9da601 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -2210,8 +2210,10 @@ class Query(BaseExpression): field_names.append(f) self.set_extra_mask(extra_names) self.set_annotation_mask(annotation_names) + selected = frozenset(field_names + extra_names + annotation_names) else: field_names = [f.attname for f in self.model._meta.concrete_fields] + selected = frozenset(field_names) # Selected annotations must be known before setting the GROUP BY # clause. if self.group_by is True: @@ -2225,7 +2227,7 @@ class Query(BaseExpression): # the selected fields anymore. group_by = [] for expr in self.group_by: - if isinstance(expr, Ref) and expr.refs not in field_names: + if isinstance(expr, Ref) and expr.refs not in selected: expr = self.annotations[expr.refs] group_by.append(expr) self.group_by = tuple(group_by) |
