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 Mariusz Felisiak, 5 years ago

Cc: Mads Jensen added
Has patch: set
Keywords: window filter added
Owner: changed from nobody to Alex Aktsipetrov
Status: newassigned
Summary: Filter by window expression is sometimes allowed by ORMFilter by window expression should raise a descriptive error.
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

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

comment:2 by Mariusz Felisiak, 5 years ago

Patch needs improvement: set

comment:3 by Mariusz Felisiak, 5 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 4edad1d:

Fixed #30668 -- Made QuerySet.filter() raise NotSupportedError if any of source expressions is not filterable.

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