Opened 6 years ago

Closed 6 years ago

#29066 closed Bug (fixed)

Allow negating query expressions

Reported by: Matthew Pava Owned by: Priyansh Saxena
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Adam Johnson Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I am trying to negate the sum of values in my model, and the workaround is to multiply by Value(-1).

I get this error when I try to annotate by -Sum('field'):

bad operand type for unary -: 'Sum'

Change History (8)

comment:1 by Simon Charette, 6 years ago

Triage Stage: UnreviewedAccepted

I guess we could add support for __neg__, in the mean time Sum('field') * -1 which goes through __mul__ should work just fine.

comment:2 by Priyansh Saxena, 6 years ago

Owner: changed from nobody to Priyansh Saxena
Status: newassigned

comment:3 by Priyansh Saxena, 6 years ago

Has patch: set
Last edited 6 years ago by Tim Graham (previous) (diff)

comment:4 by Adam Johnson, 6 years ago

Cc: Adam Johnson added

comment:5 by Priyansh Saxena, 6 years ago

Needs tests: set

comment:6 by Adam Johnson, 6 years ago

Needs tests: unset
Triage Stage: AcceptedReady for checkin

comment:7 by Tim Graham, 6 years ago

Summary: Sum does not support __neg__Allow negating query expressions

comment:8 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In 617d5f41:

Fixed #29066 -- Allowed negating query expressions.

Note: See TracTickets for help on using tickets.
Back to Top