summaryrefslogtreecommitdiff
path: root/tests/expressions_window/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/expressions_window/tests.py')
-rw-r--r--tests/expressions_window/tests.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/tests/expressions_window/tests.py b/tests/expressions_window/tests.py
index 580d038e29..4df58bf27d 100644
--- a/tests/expressions_window/tests.py
+++ b/tests/expressions_window/tests.py
@@ -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):