Code

#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.

Attachments (0)

Change History (1)

comment:1 Changed 19 months ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

This sounds like #10060 to me.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.