diff --git a/django/contrib/auth/backends.py b/django/contrib/auth/backends.py index 4adcf35051..dd3c2e527b 100644 --- a/django/contrib/auth/backends.py +++ b/django/contrib/auth/backends.py @@ -1,10 +1,6 @@ -import warnings - from django.contrib.auth import get_user_model from django.contrib.auth.models import Permission from django.db.models import Exists, OuterRef, Q -from django.utils.deprecation import RemovedInDjango50Warning -from django.utils.inspect import func_supports_parameter UserModel = get_user_model() @@ -211,19 +207,7 @@ class RemoteUserBackend(ModelBackend): user = UserModel._default_manager.get_by_natural_key(username) except UserModel.DoesNotExist: pass - - # RemovedInDjango50Warning: When the deprecation ends, replace with: - # user = self.configure_user(request, user, created=created) - if func_supports_parameter(self.configure_user, "created"): - user = self.configure_user(request, user, created=created) - else: - warnings.warn( - f"`created=True` must be added to the signature of " - f"{self.__class__.__qualname__}.configure_user().", - category=RemovedInDjango50Warning, - ) - if created: - user = self.configure_user(request, user) + user = self.configure_user(request, user, created=created) return user if self.user_can_authenticate(user) else None def clean_username(self, username): diff --git a/docs/releases/5.0.txt b/docs/releases/5.0.txt index a5c5916511..ed82f62640 100644 --- a/docs/releases/5.0.txt +++ b/docs/releases/5.0.txt @@ -324,3 +324,6 @@ to remove usage of these features. objects without providing the ``chunk_size`` argument is no longer allowed. * Passing unsaved model instances to related filters is no longer allowed. + +* ``created=True`` is required in the signature of + ``RemoteUserBackend.configure_user()`` subclasses. diff --git a/tests/auth_tests/test_remote_user.py b/tests/auth_tests/test_remote_user.py index 9e6e0dce20..d923f5d60b 100644 --- a/tests/auth_tests/test_remote_user.py +++ b/tests/auth_tests/test_remote_user.py @@ -6,14 +6,7 @@ from django.contrib.auth.backends import RemoteUserBackend from django.contrib.auth.middleware import RemoteUserMiddleware from django.contrib.auth.models import User from django.middleware.csrf import _get_new_csrf_string, _mask_cipher_secret -from django.test import ( - Client, - TestCase, - ignore_warnings, - modify_settings, - override_settings, -) -from django.utils.deprecation import RemovedInDjango50Warning +from django.test import Client, TestCase, modify_settings, override_settings @override_settings(ROOT_URLCONF="auth_tests.urls") @@ -279,34 +272,6 @@ class RemoteUserCustomTest(RemoteUserTest): self.assertEqual(newuser.email, "user@example.com") -# RemovedInDjango50Warning. -class CustomRemoteUserNoCreatedArgumentBackend(CustomRemoteUserBackend): - def configure_user(self, request, user): - return super().configure_user(request, user) - - -@ignore_warnings(category=RemovedInDjango50Warning) -class RemoteUserCustomNoCreatedArgumentTest(RemoteUserTest): - backend = "auth_tests.test_remote_user.CustomRemoteUserNoCreatedArgumentBackend" - - -@override_settings(ROOT_URLCONF="auth_tests.urls") -@modify_settings( - AUTHENTICATION_BACKENDS={ - "append": "auth_tests.test_remote_user.CustomRemoteUserNoCreatedArgumentBackend" - }, - MIDDLEWARE={"append": "django.contrib.auth.middleware.RemoteUserMiddleware"}, -) -class RemoteUserCustomNoCreatedArgumentDeprecationTest(TestCase): - def test_known_user_sync(self): - msg = ( - "`created=True` must be added to the signature of " - "CustomRemoteUserNoCreatedArgumentBackend.configure_user()." - ) - with self.assertWarnsMessage(RemovedInDjango50Warning, msg): - self.client.get("/remote_user/", **{RemoteUserTest.header: "newuser"}) - - class CustomHeaderMiddleware(RemoteUserMiddleware): """ Middleware that overrides custom HTTP auth user header.