Refs #26601 -- Deprecated old-style middleware.

This commit is contained in:
Tim Graham 2016-05-09 13:13:55 -04:00
parent 9baf692a58
commit ece4d24f8e
13 changed files with 50 additions and 4 deletions

View File

@ -43,6 +43,11 @@ class BaseHandler(object):
self._exception_middleware = []
if settings.MIDDLEWARE is None:
warnings.warn(
"Old-style middleware using settings.MIDDLEWARE_CLASSES is "
"deprecated. Update your middleware and use settings.MIDDLEWARE "
"instead.", RemovedInDjango20Warning
)
handler = self._legacy_get_response
for middleware_path in settings.MIDDLEWARE_CLASSES:
mw_class = import_string(middleware_path)

View File

@ -181,6 +181,9 @@ details on these changes.
``Meta.manager_inheritance_from_future`` to opt-in to this behavior will be
removed.
* Support for old-style middleware using ``settings.MIDDLEWARE_CLASSES`` will
be removed.
.. _deprecation-removed-in-1.10:
1.10

View File

@ -1860,6 +1860,12 @@ A list of middleware to use. See :doc:`/topics/http/middleware`.
``MIDDLEWARE_CLASSES``
----------------------
.. deprecated:: 1.10
Old-style middleware that uses ``settings.MIDDLEWARE_CLASSES`` are
deprecated. :ref:`Adapt old, custom middleware <upgrading-middleware>` and
use the :setting:`MIDDLEWARE` setting.
Default::
[

View File

@ -1142,6 +1142,10 @@ Miscellaneous
:meth:`Storage.generate_filename()
<django.core.files.storage.Storage.generate_filename>`).
* Old-style middleware that uses ``settings.MIDDLEWARE_CLASSES`` are
deprecated. :ref:`Adapt old, custom middleware <upgrading-middleware>` and
use the new :setting:`MIDDLEWARE` setting.
.. _removed-features-1.10:
Features removed in 1.10

View File

@ -4,6 +4,8 @@ from django.contrib.auth.models import Permission, User
from django.contrib.contenttypes.models import ContentType
from django.db.models import Q
from django.test import SimpleTestCase, TestCase, override_settings
from django.test.utils import ignore_warnings
from django.utils.deprecation import RemovedInDjango20Warning
from .settings import AUTH_MIDDLEWARE, AUTH_TEMPLATES
@ -76,6 +78,7 @@ class AuthContextProcessorTests(TestCase):
response = self.client.get('/auth_processor_no_attr_access/')
self.assertContains(response, "Session not accessed")
@ignore_warnings(category=RemovedInDjango20Warning)
@override_settings(MIDDLEWARE_CLASSES=AUTH_MIDDLEWARE, MIDDLEWARE=None)
def test_session_not_accessed_middleware_classes(self):
response = self.client.get('/auth_processor_no_attr_access/')
@ -90,6 +93,7 @@ class AuthContextProcessorTests(TestCase):
response = self.client.get('/auth_processor_attr_access/')
self.assertContains(response, "Session accessed")
@ignore_warnings(category=RemovedInDjango20Warning)
@override_settings(MIDDLEWARE_CLASSES=AUTH_MIDDLEWARE, MIDDLEWARE=None)
def test_session_is_accessed_middleware_classes(self):
response = self.client.get('/auth_processor_attr_access/')

View File

@ -6,7 +6,9 @@ from django.contrib.auth.backends import RemoteUserBackend
from django.contrib.auth.middleware import RemoteUserMiddleware
from django.contrib.auth.models import User
from django.test import TestCase, modify_settings, override_settings
from django.test.utils import ignore_warnings
from django.utils import timezone
from django.utils.deprecation import RemovedInDjango20Warning
@override_settings(ROOT_URLCONF='auth_tests.urls')
@ -151,6 +153,7 @@ class RemoteUserTest(TestCase):
self.assertTrue(response.context['user'].is_anonymous)
@ignore_warnings(category=RemovedInDjango20Warning)
@override_settings(MIDDLEWARE=None)
class RemoteUserTestMiddlewareClasses(RemoteUserTest):

View File

@ -2,6 +2,8 @@ from django.contrib.auth.models import User
from django.contrib.flatpages.models import FlatPage
from django.contrib.sites.models import Site
from django.test import Client, TestCase, modify_settings, override_settings
from django.test.utils import ignore_warnings
from django.utils.deprecation import RemovedInDjango20Warning
from .settings import FLATPAGES_TEMPLATES
@ -99,6 +101,7 @@ class FlatpageCSRFTests(TestCase):
self.assertEqual(response.status_code, 404)
@ignore_warnings(category=RemovedInDjango20Warning)
@override_settings(
MIDDLEWARE=None,
MIDDLEWARE_CLASSES=[

View File

@ -3,6 +3,8 @@ from django.contrib.auth.models import User
from django.contrib.flatpages.models import FlatPage
from django.contrib.sites.models import Site
from django.test import TestCase, modify_settings, override_settings
from django.test.utils import ignore_warnings
from django.utils.deprecation import RemovedInDjango20Warning
from .settings import FLATPAGES_TEMPLATES
@ -107,6 +109,7 @@ class FlatpageMiddlewareTests(TestDataMixin, TestCase):
self.assertContains(response, "<p>Isn't it special!</p>")
@ignore_warnings(category=RemovedInDjango20Warning)
@override_settings(
MIDDLEWARE=None,
MIDDLEWARE_CLASSES=[
@ -189,6 +192,7 @@ class FlatpageMiddlewareAppendSlashTests(TestDataMixin, TestCase):
self.assertContains(response, "<p>Root</p>")
@ignore_warnings(category=RemovedInDjango20Warning)
@override_settings(
MIDDLEWARE=None,
MIDDLEWARE_CLASSES=[

View File

@ -7,8 +7,8 @@ from django.http import HttpResponse
from django.template import engines
from django.template.response import TemplateResponse
from django.test import RequestFactory, SimpleTestCase, override_settings
from django.test.utils import patch_logger
from django.utils.deprecation import MiddlewareMixin
from django.test.utils import ignore_warnings, patch_logger
from django.utils.deprecation import MiddlewareMixin, RemovedInDjango20Warning
class TestException(Exception):
@ -117,6 +117,7 @@ class NoResponseMiddleware(TestMiddleware):
super(NoResponseMiddleware, self).process_response(request, response)
@ignore_warnings(category=RemovedInDjango20Warning)
@override_settings(
ROOT_URLCONF='middleware_exceptions.urls',
MIDDLEWARE_CLASSES=['django.middleware.common.CommonMiddleware'],
@ -929,6 +930,7 @@ class MiddlewareNotUsedTests(SimpleTestCase):
self.assertEqual(len(calls), 0)
@ignore_warnings(category=RemovedInDjango20Warning)
@override_settings(
MIDDLEWARE_CLASSES=['django.middleware.common.CommonMiddleware'],
MIDDLEWARE=None,

View File

@ -5,7 +5,9 @@ from django.contrib.redirects.models import Redirect
from django.contrib.sites.models import Site
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase, modify_settings, override_settings
from django.test.utils import ignore_warnings
from django.utils import six
from django.utils.deprecation import RemovedInDjango20Warning
@modify_settings(MIDDLEWARE={'append': 'django.contrib.redirects.middleware.RedirectFallbackMiddleware'})
@ -42,11 +44,13 @@ class RedirectTests(TestCase):
response = self.client.get('/initial')
self.assertEqual(response.status_code, 410)
@ignore_warnings(category=RemovedInDjango20Warning)
@override_settings(MIDDLEWARE=None)
@modify_settings(MIDDLEWARE_CLASSES={'append': 'django.contrib.redirects.middleware.RedirectFallbackMiddleware'})
def test_redirect_middleware_classes(self):
self.test_redirect()
@ignore_warnings(category=RemovedInDjango20Warning)
@override_settings(MIDDLEWARE=None)
@modify_settings(MIDDLEWARE_CLASSES={'append': 'django.contrib.redirects.middleware.RedirectFallbackMiddleware'})
def test_more_redirects_middleware_classes(self):

View File

@ -11,8 +11,8 @@ from django.template.response import (
from django.test import (
RequestFactory, SimpleTestCase, modify_settings, override_settings,
)
from django.test.utils import require_jinja2
from django.utils.deprecation import MiddlewareMixin
from django.test.utils import ignore_warnings, require_jinja2
from django.utils.deprecation import MiddlewareMixin, RemovedInDjango20Warning
from .utils import TEMPLATE_DIR
@ -361,6 +361,7 @@ class CacheMiddlewareTest(SimpleTestCase):
self.assertNotEqual(response.content, response2.content)
@ignore_warnings(category=RemovedInDjango20Warning)
@override_settings(
MIDDLEWARE=None,
MIDDLEWARE_CLASSES=[

View File

@ -2,6 +2,8 @@ from django.template import TemplateDoesNotExist
from django.test import (
Client, RequestFactory, SimpleTestCase, override_settings,
)
from django.test.utils import ignore_warnings
from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.translation import override
from django.views.csrf import CSRF_FAILURE_TEMPLATE_NAME, csrf_failure
@ -38,6 +40,7 @@ class CsrfViewTests(SimpleTestCase):
"CSRF-verificatie mislukt. Verzoek afgebroken.",
status_code=403)
@ignore_warnings(category=RemovedInDjango20Warning)
@override_settings(
USE_I18N=True,
MIDDLEWARE=None,

View File

@ -10,9 +10,11 @@ from django.test import (
SimpleTestCase, TestCase, modify_settings, override_settings,
)
from django.test.selenium import SeleniumTestCase
from django.test.utils import ignore_warnings
from django.urls import reverse
from django.utils import six
from django.utils._os import upath
from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.translation import (
LANGUAGE_SESSION_KEY, get_language, override,
)
@ -138,6 +140,7 @@ class I18NTests(TestCase):
self.assertEqual(language_cookie['path'], '/test/')
self.assertEqual(language_cookie['max-age'], 3600 * 7 * 2)
@ignore_warnings(category=RemovedInDjango20Warning)
def test_setlang_cookie_middleware_classes(self):
# we force saving language to a cookie rather than a session
# by excluding session middleware and those which do require it
@ -187,6 +190,7 @@ class I18NTests(TestCase):
)
self.assertRedirects(response, '/en/translated/')
@ignore_warnings(category=RemovedInDjango20Warning)
@override_settings(
MIDDLEWARE=None,
MIDDLEWARE_CLASSES=[