﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
10127	select_related does not play well with annotate	sylvain.pasche@…	nobody	"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)]

}}}
"		closed	Database layer (models, ORM)	dev		fixed			Unreviewed	0	0	0	0	0	0
