Hello,
I setup a minimal project here: 
https://github.com/mcagl/minimal_django_sum_test to demonstrate the problem.

I'm working with Django 1.6.x and I noticed something that I don't 
understand.

As you can see from the github repository, I have a Tag model and a Row 
model with a m2m towards Tag and a DecimalField called amount.

If I filter Row objects for more than one Tag, and there is/are Row objects 
that have more than one Tag among the one filtered by, Sum('amount') counts 
it/them once per Tag, even if I use distinct().

Please note also that I assert, in the test, that the filtered queryset is 
composed by three Row objects, as expected, but the next assert fails, with 
40 != 30.

I added a test that instead of aggregate(Sum('amount')) does sum([x.amount 
for x in rows]) which passes.

Is this a bug in Sum() or am I missing something?

Kind regards,
Mark

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/07b8489c-c5c2-43fd-8e93-d967d0543a89%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to