Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#19290 closed Uncategorized (duplicate)

'exclude' on aggregations makes wrong SQL

Reported by: letscan@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.4
Severity: Normal Keywords: aggregation
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a query like this:

qs.annotate(num_a=Sum(field1), num_b=Sum(field2)).exclude(num_a=0, num_b=0)

the query returns fewer objects than expected. I have checked the SQL of the query and found it is wrong:

SELECT ......... HAVING (NOT SUM(field1)=0 AND NOT SUM(field2)=0) .......

while what I want is like (just as the documentation says):

SELECT ......... HAVING (NOT (SUM(field1)=0 AND SUM(field2)=0)) .......

Change History (2)

comment:1 Changed 4 years ago by Aymeric Augustin

Component: Database layer (models, ORM)ORM aggregation
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Resolution: duplicate
Status: newclosed

This looks exactly like #14971 and #10060. Please reopen if it's a different issue. Thanks!

comment:2 Changed 4 years ago by Anssi Kääriäinen

Component: ORM aggregationDatabase layer (models, ORM)
Note: See TracTickets for help on using tickets.
Back to Top