#19011: Annotating multiple Sum() objects gives wrong answer
----------------------------------------------+---------------------------
Reporter: tBuLi | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.4
Severity: Normal | Keywords: annotate, sum
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+---------------------------
This is best explained with an example:
{{{
queryset = Member.objects.annotate(payed=Sum('payment__amount'))
queryset =
Member.objects.annotate(discount=Sum('membership__discount__amount'))
}}}
These give the right payed and discount amount for the member, whereas
{{{
queryset =
Member.objects.annotate(discount=Sum('membership__discount__amount'),
payed=Sum('payment__amount'))
}}}
gives a value for payed which is a factor 2 higher, and the discount is a
factor 3 higher. Using exactly the same syntax with Count() gives the
correct answer in both cases, so I suspect something goes wrong with
Sum().
using distinct = True does not matter.
--
Ticket URL: <https://code.djangoproject.com/ticket/19011>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.