#30668: Filter by window expression is sometimes allowed by ORM
-------------------------------------+-------------------------------------
Reporter: Alex | Owner: nobody
Aktsipetrov |
Type: Bug | Status: new
Component: Database | Version: master
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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'))
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30668>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.287661539e4949c560c5f8e2a3f6bd54%40djangoproject.com.