summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2020-02-03 07:48:11 +0100
committerGitHub <noreply@github.com>2020-02-03 07:48:11 +0100
commit6b178a3e930f72069f3cda2e6a09d1b320fc09ec (patch)
tree54deb16a508e9701379a8abad3c7ce70f0d64c25 /django
parent5dabb6002ed773c150da4bd3aee756df75d218c2 (diff)
Fixed #31217 -- Made QuerySet.values()/values_list() group by not selected annotations with aggregations used in order_by().
Regression in 59b4e99dd00b9c36d56055b889f96885995e4240. Thanks Jon Dufresne for the report and Simon Charette for the review.
Diffstat (limited to 'django')
-rw-r--r--django/db/models/sql/compiler.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 3a2e29a76f..a56397a3a1 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -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)