Opened 16 years ago

Closed 16 years ago

Last modified 12 years ago

#10100 closed (fixed)

"exclude" by annotation works like "filter"

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

Description

"Exclude" by annotation does not negate lookup parameters:

>>> [g.num for g in Group.objects.annotate(num=Count('sites')).exclude(num=73)]
[73]
>>> [g.num for g in Group.objects.annotate(num=Count('sites')).filter(num=73)]
[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
True

>>> 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 site_groups.id HAVING COUNT(`urls`.`id`) = %s  ORDER BY NULL', (73,))

Change History (3)

comment:1 by Pavel Anossov, 16 years ago

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

comment:2 by Russell Keith-Magee, 16 years ago

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 by Anssi Kääriäinen, 12 years ago

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