﻿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
28395	first() adds id field to group by clause on aggregation queries	John Gresty	Botond Béres	"When evaluating an aggregation query, for example:

{{{
MyModel.objects.values('group').annotate(value=Sum('value'))
}}}

works as expected. However adding {{{first()}}} to the end will add the id field into the resulting queryset and as such the annotated value will be the value of the first row, instead of the sum of the group.


{{{
>>> MyModel.objects.create(value=10)
<MyModel: MyModel object>
>>> MyModel.objects.create(value=20)
<MyModel: MyModel object>
>>> MyModel.objects.values('group').annotate(value=Sum('value'))
<QuerySet [{'group': 0, 'value': 30}]>
>>> MyModel.objects.values('group').annotate(value=Sum('value')).first()
{'group': 0, 'value': 10}
}}}
"	Cleanup/optimization	closed	Documentation	dev	Normal	fixed		Botond Béres	Accepted	1	0	0	0	0	0
