Author: russellm
Date: 2009-01-20 06:23:48 -0600 (Tue, 20 Jan 2009)
New Revision: 9781
Modified:
django/trunk/django/db/models/sql/query.py
django/trunk/tests/regressiontests/aggregation_regress/models.py
Log:
Fixed #10064 -- Corrected handling of aggregate queries that also use
select_related(). Thanks to olivius for the report.
Modified: django/trunk/django/db/models/sql/query.py
===================================================================
--- django/trunk/django/db/models/sql/query.py 2009-01-19 20:50:31 UTC (rev
9780)
+++ django/trunk/django/db/models/sql/query.py 2009-01-20 12:23:48 UTC (rev
9781)
@@ -250,11 +250,12 @@
if self.aggregate_select:
aggregate_start = len(self.extra_select.keys()) +
len(self.select)
+ aggregate_end = aggregate_start +
len(self.aggregate_select)
row = tuple(row[:aggregate_start]) + tuple([
self.resolve_aggregate(value, aggregate)
for (alias, aggregate), value
- in zip(self.aggregate_select.items(),
row[aggregate_start:])
- ])
+ in zip(self.aggregate_select.items(),
row[aggregate_start:aggregate_end])
+ ]) + tuple(row[aggregate_end:])
yield row
Modified: django/trunk/tests/regressiontests/aggregation_regress/models.py
===================================================================
--- django/trunk/tests/regressiontests/aggregation_regress/models.py
2009-01-19 20:50:31 UTC (rev 9780)
+++ django/trunk/tests/regressiontests/aggregation_regress/models.py
2009-01-20 12:23:48 UTC (rev 9781)
@@ -147,6 +147,9 @@
>>> Book.objects.aggregate(number=Max('pages'), select=Max('pages'))
{'number': 1132, 'select': 1132}
+# Regression for #10064: select_related() plays nice with aggregates
+>>>
Book.objects.select_related('publisher').annotate(num_authors=Count('authors')).values()[0]
+{'rating': 4.0, 'isbn': u'013790395', 'name': u'Artificial Intelligence: A
Modern Approach', 'pubdate': datetime.date(1995, 1, 15), 'price':
Decimal("82.8..."), 'id': 5, 'num_authors': 2, 'publisher_id': 3, 'pages': 1132}
"""
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---