﻿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
11096	.values including related fields does not work when specified after an aggregate's .annotate	David Gouldin		"Using the following models:

{{{
class Author(models.Model):
    name = models.CharField(max_length=100)

class Book(models.Model):
    name = models.CharField(max_length=100)
    author = models.ForeignKey(Author, related_name=""books"")

}}}

This query results in an exception:

{{{
Book.objects.annotate(num_authors=Count('author')).filter(num_authors__gt=1).values('author__name')
}}}

It looks like the GROUP BY clause of the resulting sql is not getting set correctly.  This only seems to happen when .values comes ''after'' .annotate.
"	Bug	closed	Database layer (models, ORM)	dev	Normal	worksforme		dgouldin@… cmutel@…	Accepted	0	0	0	0	0	0
