mirror of
https://github.com/django/django.git
synced 2025-12-02 16:16:01 +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
|
|
@ -195,8 +195,9 @@ class Query(object):
|
|||
Unpickling support.
|
||||
"""
|
||||
# Rebuild list of field instances
|
||||
opts = obj_dict['model']._meta
|
||||
obj_dict['select_fields'] = [
|
||||
name is not None and obj_dict['model']._meta.get_field(name) or None
|
||||
name is not None and opts.get_field(name) or None
|
||||
for name in obj_dict['select_fields']
|
||||
]
|
||||
|
||||
|
|
@ -707,13 +708,20 @@ class Query(object):
|
|||
# "group by", "where" and "having".
|
||||
self.where.relabel_aliases(change_map)
|
||||
self.having.relabel_aliases(change_map)
|
||||
for columns in (self.select, self.aggregates.values(), self.group_by or []):
|
||||
for columns in [self.select, self.group_by or []]:
|
||||
for pos, col in enumerate(columns):
|
||||
if isinstance(col, (list, tuple)):
|
||||
old_alias = col[0]
|
||||
columns[pos] = (change_map.get(old_alias, old_alias), col[1])
|
||||
else:
|
||||
col.relabel_aliases(change_map)
|
||||
for mapping in [self.aggregates]:
|
||||
for key, col in mapping.items():
|
||||
if isinstance(col, (list, tuple)):
|
||||
old_alias = col[0]
|
||||
mapping[key] = (change_map.get(old_alias, old_alias), col[1])
|
||||
else:
|
||||
col.relabel_aliases(change_map)
|
||||
|
||||
# 2. Rename the alias in the internal table/alias datastructures.
|
||||
for old_alias, new_alias in change_map.iteritems():
|
||||
|
|
@ -1075,6 +1083,8 @@ class Query(object):
|
|||
|
||||
|
||||
if having_clause:
|
||||
if (alias, col) not in self.group_by:
|
||||
self.group_by.append((alias, col))
|
||||
self.having.add((Constraint(alias, col, field), lookup_type, value),
|
||||
connector)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue