Opened 16 years ago
Last modified 8 months ago
#10060 new
Multiple table annotation failure — at Initial Version
Reported by: | 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 |
Pull Requests: | |||
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).
According to the ticket's flags, the next step(s) to move this issue forward are:
- To provide a patch by sending a pull request. Claim the ticket when you start working so that someone else doesn't duplicate effort. Before sending a pull request, review your work against the patch review checklist. Check the "Has patch" flag on the ticket after sending a pull request and include a link to the pull request in the ticket comment when making that update. The usual format is:
[https://github.com/django/django/pull/#### PR]
.