#28395: first() adds id field to group by clause on aggregation queries
-------------------------------------+-------------------------------------
               Reporter:  John       |          Owner:  nobody
  Gresty                             |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  1.11
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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}
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28395>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.68ad3d188333de92b33e758a95aeb995%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to