diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py index b206c70b05..fbe7a8b8a0 100644 --- a/django/core/handlers/base.py +++ b/django/core/handlers/base.py @@ -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) diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index d4bde35a46..99c9db5e50 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -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 diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt index a7801f715c..b7ba1f6b5e 100644 --- a/docs/ref/settings.txt +++ b/docs/ref/settings.txt @@ -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 ` and + use the :setting:`MIDDLEWARE` setting. + Default:: [ diff --git a/docs/releases/1.10.txt b/docs/releases/1.10.txt index 13e5f44d5b..a73790b9b8 100644 --- a/docs/releases/1.10.txt +++ b/docs/releases/1.10.txt @@ -1142,6 +1142,10 @@ Miscellaneous :meth:`Storage.generate_filename() `). +* Old-style middleware that uses ``settings.MIDDLEWARE_CLASSES`` are + deprecated. :ref:`Adapt old, custom middleware ` and + use the new :setting:`MIDDLEWARE` setting. + .. _removed-features-1.10: Features removed in 1.10 diff --git a/tests/auth_tests/test_context_processors.py b/tests/auth_tests/test_context_processors.py index d1db63c7b2..150703440b 100644 --- a/tests/auth_tests/test_context_processors.py +++ b/tests/auth_tests/test_context_processors.py @@ -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/') diff --git a/tests/auth_tests/test_remote_user.py b/tests/auth_tests/test_remote_user.py index 1cb7666a49..2b5bf32d74 100644 --- a/tests/auth_tests/test_remote_user.py +++ b/tests/auth_tests/test_remote_user.py @@ -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): diff --git a/tests/flatpages_tests/test_csrf.py b/tests/flatpages_tests/test_csrf.py index b4ae186d0c..c71d9dfca6 100644 --- a/tests/flatpages_tests/test_csrf.py +++ b/tests/flatpages_tests/test_csrf.py @@ -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=[ diff --git a/tests/flatpages_tests/test_middleware.py b/tests/flatpages_tests/test_middleware.py index 8d04076af6..bba7d6becf 100644 --- a/tests/flatpages_tests/test_middleware.py +++ b/tests/flatpages_tests/test_middleware.py @@ -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, "

Isn't it special!

") +@ignore_warnings(category=RemovedInDjango20Warning) @override_settings( MIDDLEWARE=None, MIDDLEWARE_CLASSES=[ @@ -189,6 +192,7 @@ class FlatpageMiddlewareAppendSlashTests(TestDataMixin, TestCase): self.assertContains(response, "

Root

") +@ignore_warnings(category=RemovedInDjango20Warning) @override_settings( MIDDLEWARE=None, MIDDLEWARE_CLASSES=[ diff --git a/tests/middleware_exceptions/tests.py b/tests/middleware_exceptions/tests.py index 13b33632f8..58ac5b965f 100644 --- a/tests/middleware_exceptions/tests.py +++ b/tests/middleware_exceptions/tests.py @@ -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, diff --git a/tests/redirects_tests/tests.py b/tests/redirects_tests/tests.py index b4210ad49b..d566b69006 100644 --- a/tests/redirects_tests/tests.py +++ b/tests/redirects_tests/tests.py @@ -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): diff --git a/tests/template_tests/test_response.py b/tests/template_tests/test_response.py index c2ece4b2a8..19e8e1fe99 100644 --- a/tests/template_tests/test_response.py +++ b/tests/template_tests/test_response.py @@ -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=[ diff --git a/tests/view_tests/tests/test_csrf.py b/tests/view_tests/tests/test_csrf.py index 22bf96529f..fdd9715476 100644 --- a/tests/view_tests/tests/test_csrf.py +++ b/tests/view_tests/tests/test_csrf.py @@ -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, diff --git a/tests/view_tests/tests/test_i18n.py b/tests/view_tests/tests/test_i18n.py index a50b7d6460..e1cf44782d 100644 --- a/tests/view_tests/tests/test_i18n.py +++ b/tests/view_tests/tests/test_i18n.py @@ -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=[