Opened 12 years ago
Closed 12 years ago
#19011 closed Bug (duplicate)
Annotating multiple Sum() objects gives wrong answer
Reported by: | tBuLi | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.4 |
Severity: | Normal | Keywords: | annotate, sum |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
Note:
See TracTickets
for help on using tickets.
This sounds like #10060 to me.