mirror of
https://github.com/django/django.git
synced 2025-07-31 17:14:14 +00:00
Fixed a suite of errors in the ORM -- a) fixed calling values_list().values_list() and changing whether the results are flat, b) fixed an issue with fields on the left-hand side of what becomes the HAVING clause not being included in the GROUP BY clause, and c) fixed a bug with fields from values() calls not being included in the GROUP BY clause. This fixed the recent test failures under postgresql.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14715 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
3cbaf3c2b6
commit
678f626c24
6 changed files with 66 additions and 21 deletions
|
@ -469,9 +469,11 @@ class SQLCompiler(object):
|
|||
qn = self.quote_name_unless_alias
|
||||
result, params = [], []
|
||||
if self.query.group_by is not None:
|
||||
if len(self.query.model._meta.fields) == len(self.query.select) and \
|
||||
self.connection.features.allows_group_by_pk:
|
||||
self.query.group_by = [(self.query.model._meta.db_table, self.query.model._meta.pk.column)]
|
||||
if (len(self.query.model._meta.fields) == len(self.query.select) and
|
||||
self.connection.features.allows_group_by_pk):
|
||||
self.query.group_by = [
|
||||
(self.query.model._meta.db_table, self.query.model._meta.pk.column)
|
||||
]
|
||||
|
||||
group_by = self.query.group_by or []
|
||||
|
||||
|
@ -479,11 +481,13 @@ class SQLCompiler(object):
|
|||
for extra_select, extra_params in self.query.extra_select.itervalues():
|
||||
extra_selects.append(extra_select)
|
||||
params.extend(extra_params)
|
||||
for col in group_by + self.query.related_select_cols + extra_selects:
|
||||
cols = (group_by + self.query.select +
|
||||
self.query.related_select_cols + extra_selects)
|
||||
for col in cols:
|
||||
if isinstance(col, (list, tuple)):
|
||||
result.append('%s.%s' % (qn(col[0]), qn(col[1])))
|
||||
elif hasattr(col, 'as_sql'):
|
||||
result.append(col.as_sql(qn))
|
||||
result.append(col.as_sql(qn, self.connection))
|
||||
else:
|
||||
result.append('(%s)' % str(col))
|
||||
return result, params
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue