diff --git a/django/contrib/auth/middleware.py b/django/contrib/auth/middleware.py index df4c0d41da..bd8a1c1080 100644 --- a/django/contrib/auth/middleware.py +++ b/django/contrib/auth/middleware.py @@ -1,8 +1,7 @@ -import warnings from functools import partial from urllib.parse import urlsplit -from asgiref.sync import iscoroutinefunction, markcoroutinefunction, sync_to_async +from asgiref.sync import iscoroutinefunction, markcoroutinefunction from django.conf import settings from django.contrib import auth @@ -11,7 +10,7 @@ from django.contrib.auth.backends import RemoteUserBackend from django.contrib.auth.views import redirect_to_login from django.core.exceptions import ImproperlyConfigured from django.shortcuts import resolve_url -from django.utils.deprecation import MiddlewareMixin, RemovedInDjango61Warning +from django.utils.deprecation import MiddlewareMixin from django.utils.functional import SimpleLazyObject @@ -172,20 +171,6 @@ class RemoteUserMiddleware: auth.login(request, user) async def __acall__(self, request): - # RemovedInDjango61Warning. - if ( - self.__class__.process_request is not RemoteUserMiddleware.process_request - and self.__class__.aprocess_request is RemoteUserMiddleware.aprocess_request - ): - warnings.warn( - "Support for subclasses of RemoteUserMiddleware that override " - "process_request() without overriding aprocess_request() is " - "deprecated.", - category=RemovedInDjango61Warning, - stacklevel=2, - ) - await sync_to_async(self.process_request, thread_sensitive=True)(request) - return await self.get_response(request) await self.aprocess_request(request) return await self.get_response(request) diff --git a/docs/releases/6.1.txt b/docs/releases/6.1.txt index 5b98cda2a6..70da3ade6a 100644 --- a/docs/releases/6.1.txt +++ b/docs/releases/6.1.txt @@ -278,3 +278,7 @@ to remove usage of these features. ``django.contrib.postgres.aggregates.JSONBAgg``, and ``django.contrib.postgres.aggregates.StringAgg`` are removed in favor of the ``order_by`` parameter. + +* Support for subclasses of ``RemoteUserMiddleware`` that override + ``process_request()`` without overriding ``aprocess_request()`` is + removed. diff --git a/tests/auth_tests/test_remote_user.py b/tests/auth_tests/test_remote_user.py index c871ea7dc8..4a97fc2120 100644 --- a/tests/auth_tests/test_remote_user.py +++ b/tests/auth_tests/test_remote_user.py @@ -13,7 +13,6 @@ from django.test import ( modify_settings, override_settings, ) -from django.utils.deprecation import RemovedInDjango61Warning @override_settings(ROOT_URLCONF="auth_tests.urls") @@ -490,51 +489,3 @@ class PersistentRemoteUserTest(RemoteUserTest): response = await self.async_client.get("/remote_user/") self.assertFalse(response.context["user"].is_anonymous) self.assertEqual(response.context["user"].username, "knownuser") - - -# RemovedInDjango61Warning. -class CustomProcessRequestMiddlewareSyncOnly(RemoteUserMiddleware): - def process_request(self, request): - raise NotImplementedError("process_request has not been implemented.") - - -# RemovedInDjango61Warning. -class CustomProcessRequestMiddleware(RemoteUserMiddleware): - def process_request(self, request): - raise NotImplementedError("process_request has not been implemented.") - - async def aprocess_request(self, request): - raise NotImplementedError("aprocess_request has not been implemented.") - - -# RemovedInDjango61Warning. -@override_settings(ROOT_URLCONF="auth_tests.urls") -class CustomProcessRequestMiddlewareTest(TestCase): - @modify_settings( - MIDDLEWARE={ - "append": "auth_tests.test_remote_user." - "CustomProcessRequestMiddlewareSyncOnly" - } - ) - async def test_async_warns_sync_only_middleware(self): - deprecation_msg = ( - "Support for subclasses of RemoteUserMiddleware that override " - "process_request() without overriding aprocess_request() is " - "deprecated." - ) - error_msg = "process_request has not been implemented." - with ( - self.assertWarnsMessage(RemovedInDjango61Warning, deprecation_msg), - self.assertRaisesMessage(NotImplementedError, error_msg), - ): - await self.async_client.get("/remote_user/") - - @modify_settings( - MIDDLEWARE={ - "append": "auth_tests.test_remote_user.CustomProcessRequestMiddleware" - } - ) - async def test_async_no_warning_sync_and_async_middleware(self): - error_msg = "aprocess_request has not been implemented." - with self.assertRaisesMessage(NotImplementedError, error_msg): - await self.async_client.get("/remote_user/")