Opened 7 years ago

Last modified 7 years ago

#28731 closed Bug

Passing an empty Q() to a When inside a Case causes an OperationError — at Version 1

Reported by: Tom van Bussel Owned by: nobody
Component: Database layer (models, ORM) Version: 1.11
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 (last modified by Tom van Bussel)

The following code causes an OperationError:

q = Q() # Dynamically constructed, possibly empty
x = TestModel.objects.annotate(test_name=Case(When(q, then=Value(True)), default=Value(False), output_field=BooleanField())).all()
print(x)

The code above results in a SQL query which contains CASE WHEN THEN, with nothing between the WHEN and THEN.

Change History (1)

comment:1 by Tom van Bussel, 7 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top