Opened 7 years ago

Closed 7 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

Description

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'):

TypeError
bad operand type for unary -: 'Sum'

Change History (8)

comment:1 by Simon Charette, 7 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, 7 years ago

Owner: changed from nobody to Priyansh Saxena
Status: newassigned

comment:3 by Priyansh Saxena, 7 years ago

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

comment:4 by Adam Johnson, 7 years ago

Cc: Adam Johnson added

comment:5 by Priyansh Saxena, 7 years ago

Needs tests: set

comment:6 by Adam Johnson, 7 years ago

Needs tests: unset
Triage Stage: AcceptedReady for checkin

comment:7 by Tim Graham, 7 years ago

Summary: Sum does not support __neg__Allow negating query expressions

comment:8 by Tim Graham <timograham@…>, 7 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