mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #31566 -- Fixed aliases crash when chaining values()/values_list() after annotate() with aggregations and subqueries.
Subquery annotation references must be resolved if they are excluded
from the GROUP BY clause by a following .values() call.
Regression in fb3f034f1c.
Thanks Makina Corpus for the report.
This commit is contained in:
committed by
Mariusz Felisiak
parent
e536fa5ce1
commit
42c08ee465
@@ -2155,6 +2155,15 @@ class Query(BaseExpression):
|
||||
# SELECT clause which is about to be cleared.
|
||||
self.set_group_by(allow_aliases=False)
|
||||
self.clear_select_fields()
|
||||
elif self.group_by:
|
||||
# Resolve GROUP BY annotation references if they are not part of
|
||||
# the selected fields anymore.
|
||||
group_by = []
|
||||
for expr in self.group_by:
|
||||
if isinstance(expr, Ref) and expr.refs not in field_names:
|
||||
expr = self.annotations[expr.refs]
|
||||
group_by.append(expr)
|
||||
self.group_by = tuple(group_by)
|
||||
|
||||
self.values_select = tuple(field_names)
|
||||
self.add_fields(field_names, True)
|
||||
|
||||
Reference in New Issue
Block a user