Opened 17 years ago
Last modified 16 months ago
#10060 new
Multiple table annotation failure — at Version 3
| 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 |
Description (last modified by )
Annotating across multiple tables results in wrong answers. i.e.
In [110]: total = Branch.objects.all().annotate(total=Sum('center__client__loan__amount'))
In [111]: total[0].total
Out[111]: 3433000
In [112]: repaid = Branch.objects.all().annotate(repaid=Sum('center__client__loan__payment_schedule__payments__principal'))
In [113]: repaid[0].repaid
Out[113]: 1976320.0
In [114]: both = Branch.objects.all().annotate(total=Sum('center__client__loan__amount'),repaid=Sum('center__client__loan__payment_schedule__payments__principal'))
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 (4)
comment:1 by , 17 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 17 years ago
if you unzip agg_test.tar.gz, start a django shell in the project and run count.py in the shell, you will see the error being reproduced.
cheers
Sid
Note:
See TracTickets
for help on using tickets.
It would help a great deal if you gave us the actual models and sample data. You have highlighted an inconsistency, but you haven't given us the ability to reproduce the failure.