mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #30988 -- Deprecated the InvalidQuery exception.
It was barely documented without pointers at its defining location and was abused to prevent misuse of the QuerySet field deferring feature.
This commit is contained in:
parent
cbe4d6203f
commit
11e327a3ff
8 changed files with 82 additions and 15 deletions
30
tests/queries/test_deprecation.py
Normal file
30
tests/queries/test_deprecation.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
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)
|
Loading…
Add table
Add a link
Reference in a new issue