[Django] #30394: Mutiple annotation with Sum return wrong values.

18 views
Skip to first unread message

Django

unread,
Apr 24, 2019, 4:29:07 AM4/24/19
to django-...@googlegroups.com
#30394: Mutiple annotation with Sum return wrong values.
-------------------------------------+-------------------------------------
Reporter: Gouri | Owner: nobody
Javed |
Type: Bug | Status: new
Component: Database | Version: 2.2
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
UserRoleAccount.objects.filter(pk='24f4a032-3f83-4123-8330-fa60fcbb880c').aggregate(
given_count=Sum(
Case(When(user_observations_given__group=grp, then=1),
output_field=IntegerField())
),
taken_count=Sum(
Case(When(user_observations_taken__group=grp, then=1),
output_field=IntegerField())
)
)

--
Ticket URL: <https://code.djangoproject.com/ticket/30394>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 24, 2019, 4:30:56 AM4/24/19
to django-...@googlegroups.com
#30394: Mutiple annotation with Sum return wrong values.
-------------------------------------+-------------------------------------
Reporter: Gouri Javed | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Gouri Javed):

* version: 2.2 => 1.11


Old description:

> UserRoleAccount.objects.filter(pk='24f4a032-3f83-4123-8330-fa60fcbb880c').aggregate(
> given_count=Sum(
> Case(When(user_observations_given__group=grp, then=1),
> output_field=IntegerField())
> ),
> taken_count=Sum(
> Case(When(user_observations_taken__group=grp, then=1),
> output_field=IntegerField())
> )
> )

New description:

UserRoleAccount.objects.annotate(count=Sum(Case(When(user_observations_taken__group=grp,then=1)),default=0,output_field=IntegerField(),distinct=True)).annotate(count1=Sum(Case(When(user_observations_given__group=grp,then=1)),default=0,output_field=IntegerField(),distinct=True))

--

--
Ticket URL: <https://code.djangoproject.com/ticket/30394#comment:1>

Django

unread,
Apr 24, 2019, 4:47:12 AM4/24/19
to django-...@googlegroups.com
#30394: Mutiple annotation with Sum return wrong values.
-------------------------------------+-------------------------------------
Reporter: Gouri Javed | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* status: new => closed
* resolution: => duplicate


Comment:

[https://docs.djangoproject.com/en/2.2/topics/db/aggregation/#combining-
multiple-aggregations As documented] this is a duplicate of #10060.

--
Ticket URL: <https://code.djangoproject.com/ticket/30394#comment:2>

Reply all
Reply to author
Forward
0 new messages