summaryrefslogtreecommitdiff
path: root/tests/expressions_window/tests.py
diff options
context:
space:
mode:
authorAlex Aktsipetrov <alex.akts@gmail.com>2019-12-05 19:08:47 +0300
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-12-06 13:52:16 +0100
commitbf12273db4e53779546e2ac7b65c0ce8e3c8a640 (patch)
tree086d6d2d46dedcf7e8438daaa8eb53f7480669cf /tests/expressions_window/tests.py
parent5708327c3769262b845730996ca2784245ada4d1 (diff)
downloaddjango-bf12273db4e53779546e2ac7b65c0ce8e3c8a640.tar.gz
Fixed #31060 -- Reallowed window expressions to be used in conditions outside of queryset filters.
Regression in 4edad1ddf6203326e0be4bdb105beecb0fe454c4. Thanks utapyngo for the report.
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):