mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #31060 -- Reallowed window expressions to be used in conditions outside of queryset filters.
Regression in 4edad1ddf6.
Thanks utapyngo for the report.
This commit is contained in:
committed by
Mariusz Felisiak
parent
5708327c37
commit
bf12273db4
@@ -4,8 +4,8 @@ from unittest import mock, skipIf, skipUnless
|
||||
from django.core.exceptions import FieldError
|
||||
from django.db import NotSupportedError, connection
|
||||
from django.db.models import (
|
||||
F, Func, OuterRef, Q, RowRange, Subquery, Value, ValueRange, Window,
|
||||
WindowFrame,
|
||||
BooleanField, Case, F, Func, OuterRef, Q, RowRange, Subquery, Value,
|
||||
ValueRange, When, Window, WindowFrame,
|
||||
)
|
||||
from django.db.models.aggregates import Avg, Max, Min, Sum
|
||||
from django.db.models.functions import (
|
||||
@@ -846,6 +846,22 @@ class NonQueryWindowTests(SimpleTestCase):
|
||||
with self.assertRaisesMessage(NotSupportedError, msg):
|
||||
qs.annotate(total=Sum('dense_rank', filter=Q(name='Jones'))).filter(total=1)
|
||||
|
||||
def test_conditional_annotation(self):
|
||||
qs = Employee.objects.annotate(
|
||||
dense_rank=Window(expression=DenseRank()),
|
||||
).annotate(
|
||||
equal=Case(
|
||||
When(id=F('dense_rank'), then=Value(True)),
|
||||
default=Value(False),
|
||||
output_field=BooleanField(),
|
||||
),
|
||||
)
|
||||
# The SQL standard disallows referencing window functions in the WHERE
|
||||
# clause.
|
||||
msg = 'Window is disallowed in the filter clause'
|
||||
with self.assertRaisesMessage(NotSupportedError, msg):
|
||||
qs.filter(equal=True)
|
||||
|
||||
def test_invalid_order_by(self):
|
||||
msg = 'order_by must be either an Expression or a sequence of expressions'
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
|
||||
Reference in New Issue
Block a user