Opened 9 years ago

Closed 9 years ago

Last modified 5 years ago

#10100 closed (fixed)

"exclude" by annotation works like "filter"

Reported by: Pavel Anossov Owned by:
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


"Exclude" by annotation does not negate lookup parameters:

>>> [g.num for g in Group.objects.annotate(num=Count('sites')).exclude(num=73)]
>>> [g.num for g in Group.objects.annotate(num=Count('sites')).filter(num=73)]

>>> e = Group.objects.annotate(num=Count('sites')).exclude(num=73).query.as_sql()
>>> f = Group.objects.annotate(num=Count('sites')).filter(num=73).query.as_sql()
>>> e == f

>>> Group.objects.annotate(num=Count('sites')).exclude(num=73).query.as_sql()
(u'SELECT (...), COUNT(`sites`.`id`) AS `num` FROM `site_groups` LEFT OUTER JOIN `sites` ON (`site_groups`.`id` = `sites`.`group_id`) GROUP BY HAVING COUNT(`urls`.`id`) = %s  ORDER BY NULL', (73,))

Change History (3)

comment:1 Changed 9 years ago by Pavel Anossov

sorry, there should be sites in HAVING as well, of course :)

comment:2 Changed 9 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

(In [9785]) Fixed #10100 -- Corrected handling of the negation required exclude() clauses that reference aggregate columns. Thanks to Anossov for the report.

comment:3 Changed 5 years ago by Anssi Kääriäinen

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