1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #31217 -- Made QuerySet.values()/values_list() group by not selected annotations with aggregations used in order_by().

Regression in 59b4e99dd0.

Thanks Jon Dufresne for the report and Simon Charette for the review.
This commit is contained in:
Mariusz Felisiak
2020-02-03 07:48:11 +01:00
committed by GitHub
parent 5dabb6002e
commit 6b178a3e93
2 changed files with 29 additions and 2 deletions

View File

@@ -123,8 +123,8 @@ class SQLCompiler:
for expr, (sql, params, is_ref) in order_by:
# Skip References to the select clause, as all expressions in the
# select clause are already part of the group by.
if not expr.contains_aggregate and not is_ref:
expressions.extend(expr.get_source_expressions())
if not is_ref:
expressions.extend(expr.get_group_by_cols())
having_group_by = self.having.get_group_by_cols() if self.having else ()
for expr in having_group_by:
expressions.append(expr)