Opened 2 years ago

Closed 2 years ago

#29066 closed Bug (fixed)

Allow negating query expressions

Reported by: Matthew Pava Owned by: Priyansh Saxena
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Adam (Chainz) 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 Changed 2 years ago by Simon Charette

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 Changed 2 years ago by Priyansh Saxena

Owner: changed from nobody to Priyansh Saxena
Status: newassigned

comment:3 Changed 2 years ago by Priyansh Saxena

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

comment:4 Changed 2 years ago by Adam (Chainz) Johnson

Cc: Adam (Chainz) Johnson added

comment:5 Changed 2 years ago by Priyansh Saxena

Needs tests: set

comment:6 Changed 2 years ago by Adam (Chainz) Johnson

Needs tests: unset
Triage Stage: AcceptedReady for checkin

comment:7 Changed 2 years ago by Tim Graham

Summary: Sum does not support __neg__Allow negating query expressions

comment:8 Changed 2 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 617d5f41:

Fixed #29066 -- Allowed negating query expressions.

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