Opened 5 years ago
Closed 5 years ago
#30668 closed Cleanup/optimization (fixed)
Filter by window expression should raise a descriptive error.
Reported by: | Alex Aktsipetrov | Owned by: | Alex Aktsipetrov |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | window filter |
Cc: | Mads Jensen | 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
Django has a check that filter does not contain window expressions.
But it is shallow, neither right side of the expression nor combined expressions are checked.
class Employee(models.Model): grade = models.IntegerField() # raises NotSupportedError Employee.objects.annotate( prev_grade=Window(expression=Lag('grade')) ).filter(prev_grade=F('grade')) # Do not raise anything, fail on database backend once executed. Employee.objects.annotate( prev_grade=Window(expression=Lag('grade')) ).filter(grade=F('prev_grade')) Employee.objects.annotate( prev_grade=Window(expression=Lag('grade')), dec_grade=F('prev_grade') - Value(1) ).filter(dec_grade=F('grade'))
Change History (4)
comment:1 by , 5 years ago
Cc: | added |
---|---|
Has patch: | set |
Keywords: | window filter added |
Owner: | changed from | to
Status: | new → assigned |
Summary: | Filter by window expression is sometimes allowed by ORM → Filter by window expression should raise a descriptive error. |
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
comment:2 by , 5 years ago
Patch needs improvement: | set |
---|
comment:3 by , 5 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Note:
See TracTickets
for help on using tickets.
Thanks for this report. Agreed, we should raise a helpful message because it is currently unsupported (see also a ticket #28333 to support this feature).
PR