mirror of
https://github.com/django/django.git
synced 2025-09-25 07:59:11 +00:00
Refs #36390 -- Removed support for RemoteUserMiddleware subclasses missing aprocess_request().
Per deprecation timeline.
This commit is contained in:
parent
7d7e5cd055
commit
0655d958bd
@ -1,8 +1,7 @@
|
|||||||
import warnings
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from urllib.parse import urlsplit
|
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.conf import settings
|
||||||
from django.contrib import auth
|
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.contrib.auth.views import redirect_to_login
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.shortcuts import resolve_url
|
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
|
from django.utils.functional import SimpleLazyObject
|
||||||
|
|
||||||
|
|
||||||
@ -172,20 +171,6 @@ class RemoteUserMiddleware:
|
|||||||
auth.login(request, user)
|
auth.login(request, user)
|
||||||
|
|
||||||
async def __acall__(self, request):
|
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)
|
await self.aprocess_request(request)
|
||||||
return await self.get_response(request)
|
return await self.get_response(request)
|
||||||
|
|
||||||
|
@ -278,3 +278,7 @@ to remove usage of these features.
|
|||||||
``django.contrib.postgres.aggregates.JSONBAgg``, and
|
``django.contrib.postgres.aggregates.JSONBAgg``, and
|
||||||
``django.contrib.postgres.aggregates.StringAgg`` are removed in favor
|
``django.contrib.postgres.aggregates.StringAgg`` are removed in favor
|
||||||
of the ``order_by`` parameter.
|
of the ``order_by`` parameter.
|
||||||
|
|
||||||
|
* Support for subclasses of ``RemoteUserMiddleware`` that override
|
||||||
|
``process_request()`` without overriding ``aprocess_request()`` is
|
||||||
|
removed.
|
||||||
|
@ -13,7 +13,6 @@ from django.test import (
|
|||||||
modify_settings,
|
modify_settings,
|
||||||
override_settings,
|
override_settings,
|
||||||
)
|
)
|
||||||
from django.utils.deprecation import RemovedInDjango61Warning
|
|
||||||
|
|
||||||
|
|
||||||
@override_settings(ROOT_URLCONF="auth_tests.urls")
|
@override_settings(ROOT_URLCONF="auth_tests.urls")
|
||||||
@ -490,51 +489,3 @@ class PersistentRemoteUserTest(RemoteUserTest):
|
|||||||
response = await self.async_client.get("/remote_user/")
|
response = await self.async_client.get("/remote_user/")
|
||||||
self.assertFalse(response.context["user"].is_anonymous)
|
self.assertFalse(response.context["user"].is_anonymous)
|
||||||
self.assertEqual(response.context["user"].username, "knownuser")
|
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/")
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user