diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-01-07 20:56:49 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-01-14 17:50:04 +0100 |
| commit | 68e3ca13d771a8f08a8d1c272308cd44b4dcfa76 (patch) | |
| tree | 4c2b0ad92f82bfd03afb6e084545b077e84a0678 | |
| parent | 396da8b94c62cf955ab401eb40a952b7edba0376 (diff) | |
Refs #30988 -- Removed InvalidQuery exception per deprecation timeline.
| -rw-r--r-- | django/db/models/query_utils.py | 30 | ||||
| -rw-r--r-- | docs/releases/4.0.txt | 2 | ||||
| -rw-r--r-- | tests/queries/test_deprecation.py | 30 |
3 files changed, 3 insertions, 59 deletions
diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py index f7c6d74e72..c2623f099f 100644 --- a/django/db/models/query_utils.py +++ b/django/db/models/query_utils.py @@ -8,13 +8,11 @@ circular import difficulties. import copy import functools import inspect -import warnings from collections import namedtuple -from django.core.exceptions import FieldDoesNotExist, FieldError +from django.core.exceptions import FieldError from django.db.models.constants import LOOKUP_SEP from django.utils import tree -from django.utils.deprecation import RemovedInDjango40Warning # PathInfo is used when converting lookups (fk__somecol). The contents # describe the relation in Model terms (model Options and Fields for both @@ -22,32 +20,6 @@ from django.utils.deprecation import RemovedInDjango40Warning PathInfo = namedtuple('PathInfo', 'from_opts to_opts target_fields join_field m2m direct filtered_relation') -class InvalidQueryType(type): - @property - def _subclasses(self): - return (FieldDoesNotExist, FieldError) - - def __warn(self): - warnings.warn( - 'The InvalidQuery exception class is deprecated. Use ' - 'FieldDoesNotExist or FieldError instead.', - category=RemovedInDjango40Warning, - stacklevel=4, - ) - - def __instancecheck__(self, instance): - self.__warn() - return isinstance(instance, self._subclasses) or super().__instancecheck__(instance) - - def __subclasscheck__(self, subclass): - self.__warn() - return issubclass(subclass, self._subclasses) or super().__subclasscheck__(subclass) - - -class InvalidQuery(Exception, metaclass=InvalidQueryType): - pass - - def subclasses(cls): yield cls for subclass in cls.__subclasses__(): diff --git a/docs/releases/4.0.txt b/docs/releases/4.0.txt index ba90639928..2231bd5e2d 100644 --- a/docs/releases/4.0.txt +++ b/docs/releases/4.0.txt @@ -271,3 +271,5 @@ to remove usage of these features. * The :lookup:`isnull` lookup no longer allows using non-boolean values as the right-hand side. + +* The ``django.db.models.query_utils.InvalidQuery`` exception class is removed. diff --git a/tests/queries/test_deprecation.py b/tests/queries/test_deprecation.py deleted file mode 100644 index 1dc8031fa7..0000000000 --- a/tests/queries/test_deprecation.py +++ /dev/null @@ -1,30 +0,0 @@ -from contextlib import contextmanager - -from django.core.exceptions import FieldDoesNotExist, FieldError -from django.db.models.query_utils import InvalidQuery -from django.test import SimpleTestCase -from django.utils.deprecation import RemovedInDjango40Warning - - -class InvalidQueryTests(SimpleTestCase): - @contextmanager - def assert_warns(self): - msg = ( - 'The InvalidQuery exception class is deprecated. Use ' - 'FieldDoesNotExist or FieldError instead.' - ) - with self.assertWarnsMessage(RemovedInDjango40Warning, msg): - yield - - def test_type(self): - self.assertIsInstance(InvalidQuery(), InvalidQuery) - - def test_isinstance(self): - for exception in (FieldError, FieldDoesNotExist): - with self.assert_warns(), self.subTest(exception.__name__): - self.assertIsInstance(exception(), InvalidQuery) - - def test_issubclass(self): - for exception in (FieldError, FieldDoesNotExist, InvalidQuery): - with self.assert_warns(), self.subTest(exception.__name__): - self.assertIs(issubclass(exception, InvalidQuery), True) |
