Author: russellm
Date: 2009-02-02 07:43:18 -0600 (Mon, 02 Feb 2009)
New Revision: 9805

Modified:
   django/trunk/django/db/models/query.py
   django/trunk/django/db/models/sql/query.py
   django/trunk/tests/regressiontests/aggregation_regress/models.py
Log:
Fixed #10127 -- Corrected handling of select_related() in annotate() calls. 
Thanks to Sylvain Pasche <[email protected]> for the report and test 
case.

Modified: django/trunk/django/db/models/query.py
===================================================================
--- django/trunk/django/db/models/query.py      2009-02-02 12:03:31 UTC (rev 
9804)
+++ django/trunk/django/db/models/query.py      2009-02-02 13:43:18 UTC (rev 
9805)
@@ -280,8 +280,8 @@
 
         for row in self.query.results_iter():
             if fill_cache:
-                obj, aggregate_start = get_cached_row(self.model, row,
-                                    index_start, max_depth, 
requested=requested)
+                obj, _ = get_cached_row(self.model, row,
+                                        index_start, max_depth, 
requested=requested)
             else:
                 # omit aggregates in object creation
                 obj = self.model(*row[index_start:aggregate_start])

Modified: django/trunk/django/db/models/sql/query.py
===================================================================
--- django/trunk/django/db/models/sql/query.py  2009-02-02 12:03:31 UTC (rev 
9804)
+++ django/trunk/django/db/models/sql/query.py  2009-02-02 13:43:18 UTC (rev 
9805)
@@ -698,7 +698,7 @@
         """
         qn = self.quote_name_unless_alias
         result = []
-        for col in self.group_by:
+        for col in self.group_by + self.related_select_cols:
             if isinstance(col, (list, tuple)):
                 result.append('%s.%s' % (qn(col[0]), qn(col[1])))
             elif hasattr(col, 'as_sql'):

Modified: django/trunk/tests/regressiontests/aggregation_regress/models.py
===================================================================
--- django/trunk/tests/regressiontests/aggregation_regress/models.py    
2009-02-02 12:03:31 UTC (rev 9804)
+++ django/trunk/tests/regressiontests/aggregation_regress/models.py    
2009-02-02 13:43:18 UTC (rev 9805)
@@ -194,6 +194,11 @@
 >>> Book.objects.annotate(num_authors=Count('authors')).order_by('publisher__name',
 >>>  'name')
 [<Book: Practical Django Projects>, <Book: The Definitive Guide to Django: Web 
Development Done Right>, <Book: Paradigms of Artificial Intelligence 
Programming: Case Studies in Common Lisp>, <Book: Artificial Intelligence: A 
Modern Approach>, <Book: Python Web Development with Django>, <Book: Sams Teach 
Yourself Django in 24 Hours>]
 
+# Regression for #10127 - Empty select_related() works with annotate
+>>> books = 
Book.objects.all().filter(rating__lt=4.5).select_related().annotate(Avg('authors__age'))
+>>> sorted([(b.name, b.authors__age__avg) for b in books])
+[(u'Artificial Intelligence: A Modern Approach', 51.5), (u'Practical Django 
Projects', 29.0), (u'Python Web Development with Django', 30.3...), (u'Sams 
Teach Yourself Django in 24 Hours', 45.0)]
+
 """
 }
 


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to