Skip to content

Commit bb132aa

Browse files
committed
queryset-refactor: Repaired the dates() method with extra(select=...).xi
It was broken by [7340]. Patch from Ian Kelly. Fixed django#7087. git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7468 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent dd432cc commit bb132aa

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

django/db/models/sql/subqueries.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,10 @@ def results_iter(self):
330330
from django.db.backends.util import typecast_timestamp
331331
needs_string_cast = self.connection.features.needs_datetime_string_cast
332332

333+
offset = len(self.extra_select)
333334
for rows in self.execute_sql(MULTI):
334335
for row in rows:
335-
date = row[0]
336+
date = row[offset]
336337
if resolve_columns:
337338
date = self.resolve_columns([date], fields)[0]
338339
elif needs_string_cast:

tests/regressiontests/queries/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ class Meta:
586586
>>> Tag.objects.select_related('parent').order_by('name')
587587
[<Tag: t1>, <Tag: t2>, <Tag: t3>, <Tag: t4>, <Tag: t5>]
588588
589-
Bug #6180, #6203
589+
Bug #6180, #6203 -- dates with limits and/or counts
590590
>>> Item.objects.count()
591591
4
592592
>>> Item.objects.dates('created', 'month').count()
@@ -598,6 +598,10 @@ class Meta:
598598
>>> Item.objects.dates('created', 'day')[0]
599599
datetime.datetime(2007, 12, 19, 0, 0)
600600
601+
Bug #7087 -- dates with extra select columns
602+
>>> Item.objects.dates('created', 'day').extra(select={'a': 1})
603+
[datetime.datetime(2007, 12, 19, 0, 0), datetime.datetime(2007, 12, 20, 0, 0)]
604+
601605
Test that parallel iterators work.
602606
603607
>>> qs = Tag.objects.all()

0 commit comments

Comments
 (0)