From 4a2a433e7daca1e1797b7b34d30d49ad4e09791c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anssi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Thu, 18 Dec 2014 11:02:43 +0200 Subject: [PATCH] Refs #24020 -- return expressions from get_group_by_cols() --- django/db/models/expressions.py | 4 ++-- django/db/models/sql/compiler.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index 63c2951075..81b81673d7 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -503,7 +503,7 @@ class Col(ExpressionNode): return self.__class__(relabels.get(self.alias, self.alias), self.target, self.output_field) def get_group_by_cols(self): - return [(self.alias, self.target.column)] + return [self] class Ref(ExpressionNode): @@ -529,7 +529,7 @@ class Ref(ExpressionNode): return "%s" % compiler.quote_name_unless_alias(self.refs), [] def get_group_by_cols(self): - return [(None, self.refs)] + return [self] class Date(ExpressionNode): diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index b0e3e48c15..c70dd8c5bd 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -583,10 +583,11 @@ class SQLCompiler(object): for annotation in self.query.annotation_select.values(): cols = annotation.get_group_by_cols() for col in cols: - sql = '%s.%s' % (qn(col[0]), qn(col[1])) - if sql not in seen: + sql, col_params = self.compile(col) + if sql not in seen or col_params: result.append(sql) seen.add(sql) + params.extend(col_params) return result, params