Fixed #30027 -- Errored out on Window function usage if unsupported.
This commit is contained in:
parent
ebd2fe1861
commit
64d5bafbc6
|
@ -7,6 +7,7 @@ from django.core.exceptions import EmptyResultSet, FieldError
|
|||
from django.db import connection
|
||||
from django.db.models import fields
|
||||
from django.db.models.query_utils import Q
|
||||
from django.db.utils import NotSupportedError
|
||||
from django.utils.deconstruct import deconstructible
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.hashable import make_hashable
|
||||
|
@ -1237,6 +1238,8 @@ class Window(Expression):
|
|||
|
||||
def as_sql(self, compiler, connection, template=None):
|
||||
connection.ops.check_expression_support(self)
|
||||
if not connection.features.supports_over_clause:
|
||||
raise NotSupportedError('This backend does not support window expressions.')
|
||||
expr_sql, params = compiler.compile(self.source_expression)
|
||||
window_sql, window_params = [], []
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import datetime
|
||||
from unittest import skipIf, skipUnless
|
||||
from unittest import mock, skipIf, skipUnless
|
||||
|
||||
from django.core.exceptions import FieldError
|
||||
from django.db import NotSupportedError, connection
|
||||
|
@ -821,6 +821,12 @@ class NonQueryWindowTests(SimpleTestCase):
|
|||
with self.assertRaisesMessage(NotSupportedError, msg):
|
||||
Employee.objects.annotate(dense_rank=Window(expression=DenseRank())).filter(dense_rank__gte=1)
|
||||
|
||||
def test_unsupported_backend(self):
|
||||
msg = 'This backend does not support window expressions.'
|
||||
with mock.patch.object(connection.features, 'supports_over_clause', False):
|
||||
with self.assertRaisesMessage(NotSupportedError, msg):
|
||||
Employee.objects.annotate(dense_rank=Window(expression=DenseRank())).get()
|
||||
|
||||
def test_invalid_order_by(self):
|
||||
msg = 'order_by must be either an Expression or a sequence of expressions'
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
|
|
Loading…
Reference in New Issue