From 054a44d6f0f75395bd02a21e31ea904a24750a2b Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Mon, 10 Apr 2017 18:49:27 +0200 Subject: [PATCH] Used NotSupportedError instead of DatabaseError in SQLCompiler.as_sql(). --- django/db/backends/oracle/compiler.py | 2 +- django/db/models/sql/compiler.py | 10 +++++----- tests/queries/test_qs_combinators.py | 6 +++--- tests/select_for_update/tests.py | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/django/db/backends/oracle/compiler.py b/django/db/backends/oracle/compiler.py index 52c2876fa2..b568e59e9e 100644 --- a/django/db/backends/oracle/compiler.py +++ b/django/db/backends/oracle/compiler.py @@ -20,7 +20,7 @@ class SQLCompiler(compiler.SQLCompiler): sql, params = super().as_sql(with_limits=False, with_col_aliases=with_col_aliases) elif not self.connection.features.supports_select_for_update_with_limit and self.query.select_for_update: raise NotSupportedError( - 'LIMIT/OFFSET not supported with select_for_update on this ' + 'LIMIT/OFFSET is not supported with select_for_update on this ' 'database backend.' ) else: diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 1fe19db421..f32d106def 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -430,7 +430,7 @@ class SQLCompiler: features = self.connection.features if combinator: if not getattr(features, 'supports_select_{}'.format(combinator)): - raise DatabaseError('{} not supported on this database backend.'.format(combinator)) + raise NotSupportedError('{} is not supported on this database backend.'.format(combinator)) result, params = self.get_combinator_sql(combinator, self.query.combinator_all) else: result = ['SELECT'] @@ -462,8 +462,8 @@ class SQLCompiler: if with_limits and not self.connection.features.supports_select_for_update_with_limit: raise NotSupportedError( - 'LIMIT/OFFSET not supported with select_for_update' - ' on this database backend.' + 'LIMIT/OFFSET is not supported with ' + 'select_for_update on this database backend.' ) nowait = self.query.select_for_update_nowait skip_locked = self.query.select_for_update_skip_locked @@ -471,9 +471,9 @@ class SQLCompiler: # doesn't support it, raise a DatabaseError to prevent a # possible deadlock. if nowait and not self.connection.features.has_select_for_update_nowait: - raise DatabaseError('NOWAIT is not supported on this database backend.') + raise NotSupportedError('NOWAIT is not supported on this database backend.') elif skip_locked and not self.connection.features.has_select_for_update_skip_locked: - raise DatabaseError('SKIP LOCKED is not supported on this database backend.') + raise NotSupportedError('SKIP LOCKED is not supported on this database backend.') for_update_part = self.connection.ops.for_update_sql(nowait=nowait, skip_locked=skip_locked) if for_update_part and self.connection.features.for_update_after_from: diff --git a/tests/queries/test_qs_combinators.py b/tests/queries/test_qs_combinators.py index bfb3d30825..120f9b8a9f 100644 --- a/tests/queries/test_qs_combinators.py +++ b/tests/queries/test_qs_combinators.py @@ -1,5 +1,5 @@ from django.db.models import F, IntegerField, Value -from django.db.utils import DatabaseError +from django.db.utils import DatabaseError, NotSupportedError from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature from .models import Number, ReservedName @@ -73,8 +73,8 @@ class QuerySetSetOperationTests(TestCase): def test_unsupported_intersection_raises_db_error(self): qs1 = Number.objects.all() qs2 = Number.objects.all() - msg = 'intersection not supported on this database backend' - with self.assertRaisesMessage(DatabaseError, msg): + msg = 'intersection is not supported on this database backend' + with self.assertRaisesMessage(NotSupportedError, msg): list(qs1.intersection(qs2)) def test_combining_multiple_models(self): diff --git a/tests/select_for_update/tests.py b/tests/select_for_update/tests.py index d2a32840c7..b36ff6114c 100644 --- a/tests/select_for_update/tests.py +++ b/tests/select_for_update/tests.py @@ -137,7 +137,7 @@ class SelectForUpdateTests(TransactionTestCase): DatabaseError is raised if a SELECT...FOR UPDATE NOWAIT is run on a database backend that supports FOR UPDATE but not NOWAIT. """ - with self.assertRaisesMessage(DatabaseError, 'NOWAIT is not supported on this database backend.'): + with self.assertRaisesMessage(NotSupportedError, 'NOWAIT is not supported on this database backend.'): with transaction.atomic(): Person.objects.select_for_update(nowait=True).get() @@ -148,7 +148,7 @@ class SelectForUpdateTests(TransactionTestCase): DatabaseError is raised if a SELECT...FOR UPDATE SKIP LOCKED is run on a database backend that supports FOR UPDATE but not SKIP LOCKED. """ - with self.assertRaisesMessage(DatabaseError, 'SKIP LOCKED is not supported on this database backend.'): + with self.assertRaisesMessage(NotSupportedError, 'SKIP LOCKED is not supported on this database backend.'): with transaction.atomic(): Person.objects.select_for_update(skip_locked=True).get()