Opened 7 years ago

Closed 7 years ago

Last modified 2 years ago

#10100 closed (fixed)

"exclude" by annotation works like "filter"

Reported by: 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:

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 Changed 7 years ago by Anossov

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 7 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(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 2 years ago by akaariai

  • Component changed from ORM aggregation to Database layer (models, ORM)
Note: See TracTickets for help on using tickets.
Back to Top