Opened 15 years ago

Last modified 10 months ago

#10060 new

Multiple table annotation failure — at Initial Version

Reported by: svsharma@… Owned by:
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: flosch@…, bendavis78@…, cmutel@…, daniel@…, Gabriel Hurley, sebleier@…, greg@…, mpjung@…, teemu.kurppa@…, Evstifeev Roman, michaelB, Marc Aymerich, nowak2000@…, Maxim, Gökhan Sarı, Adam M. Costello, Antoine, David Kwong Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Annotating across multiple tables results in wrong answers. i.e.

In [110]: total = Branch.objects.all().annotate(total=Sum('centerclientloanamount'))

In [111]: total[0].total
Out[111]: 3433000

In [112]: repaid = Branch.objects.all().annotate(repaid=Sum('centerclientloanpayment_schedulepaymentsprincipal'))

In [113]: repaid[0].repaid
Out[113]: 1976320.0

In [114]: both = Branch.objects.all().annotate(total=Sum('centerclientloanamount'),repaid=Sum('centerclientloanpayment_schedulepaymentsprincipal'))

In [115]: both[0].repaid
Out[115]: 1976320.0

In [116]: both[0].total
Out[116]: 98816000


Compare the output of total in 116 vs. 111 (the correct answer).

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top