#10127: select_related does not play well with annotate
------------------------------------------+---------------------------------
Reporter: [email protected] | Owner: nobody
Status: new | Milestone:
Component: Database layer (models, ORM) | Version: SVN
Keywords: | Stage: Unreviewed
Has_patch: 0 |
------------------------------------------+---------------------------------
This is with the latest trunk version. If you use {{{select_related()}}}
with a query that does an aggegation over a !ManyToMany relationship, the
resulting fields get mixed up.
This is best demonstrated by a modification in the aggregates.py test:
{{{
Index: modeltests/aggregation/models.py
===================================================================
--- modeltests/aggregation/models.py (revision 9791)
+++ modeltests/aggregation/models.py (working copy)
@@ -162,7 +162,7 @@
# Forward
# Average age of the Authors of each book with a rating less than 4.5
->>> books =
Book.objects.all().filter(rating__lt=4.5).annotate(Avg('authors__age'))
+>>> 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)]
}}}
With this modification, the test fails this way:
{{{
Failed example:
sorted([(b.name, b.authors__age__avg) for b in books])
Expected:
[(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)]
Got:
[(u'Artificial Intelligence: A Modern Approach', 7L), (u'Practical
Django Projects', 3L), (u'Python Web Development with Django', 7L),
(u'Sams Teach Yourself Django in 24 Hours', 1L)]
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/10127>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---