1
0
mirror of https://github.com/django/django.git synced 2025-07-19 17:19:12 +00:00

[1.0.X] Fixed #9985 -- qs.values_list(...).values(...) was constructing incorrect SQL.

Backport of r9717 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9718 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2009-01-08 05:51:15 +00:00
parent fe9cd02f38
commit cc76b89c59
3 changed files with 18 additions and 1 deletions

View File

@ -667,6 +667,7 @@ class ValuesQuerySet(QuerySet):
Called by the _clone() method after initializing the rest of the Called by the _clone() method after initializing the rest of the
instance. instance.
""" """
self.query.clear_select_fields()
self.extra_names = [] self.extra_names = []
if self._fields: if self._fields:
if not self.query.extra_select: if not self.query.extra_select:
@ -691,6 +692,9 @@ class ValuesQuerySet(QuerySet):
Cloning a ValuesQuerySet preserves the current fields. Cloning a ValuesQuerySet preserves the current fields.
""" """
c = super(ValuesQuerySet, self)._clone(klass, **kwargs) c = super(ValuesQuerySet, self)._clone(klass, **kwargs)
if not hasattr(c, '_fields'):
# Only clone self._fields if _fields wasn't passed into the cloning
# call directly.
c._fields = self._fields[:] c._fields = self._fields[:]
c.field_names = self.field_names c.field_names = self.field_names
c.extra_names = self.extra_names c.extra_names = self.extra_names

View File

@ -1535,6 +1535,15 @@ class BaseQuery(object):
""" """
return not (self.low_mark or self.high_mark) return not (self.low_mark or self.high_mark)
def clear_select_fields(self):
"""
Clears the list of fields to select (but not extra_select columns).
Some queryset types completely replace any existing list of select
columns.
"""
self.select = []
self.select_fields = []
def add_fields(self, field_names, allow_m2m=True): def add_fields(self, field_names, allow_m2m=True):
""" """
Adds the given (model) fields to the select set. The field names are Adds the given (model) fields to the select set. The field names are

View File

@ -1020,6 +1020,10 @@ cases).
# optimise the inner query without losing results. # optimise the inner query without losing results.
>>> Annotation.objects.exclude(tag__children__name="t2") >>> Annotation.objects.exclude(tag__children__name="t2")
[<Annotation: a2>] [<Annotation: a2>]
Bug #9985 -- qs.values_list(...).values(...) combinations should work.
>>> Note.objects.values_list("note", flat=True).values("id").order_by("id")
[{'id': 1}, {'id': 2}, {'id': 3}]
"""} """}
# In Python 2.3 and the Python 2.6 beta releases, exceptions raised in __len__ # In Python 2.3 and the Python 2.6 beta releases, exceptions raised in __len__