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 )
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.
Note:
See TracTickets
for help on using tickets.