Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New "Password-based authentication" form field displays in Django 5.1 #245

Open
simonw opened this issue Aug 13, 2024 · 9 comments
Open

Comments

@simonw
Copy link

simonw commented Aug 13, 2024

I upgraded to Django 5.1 and now my registration form looks like this:

CleanShot 2024-08-13 at 12 38 22@2x

That confusing "Password-based authentication" field is new - it looks like it was caused by this change to Django:

@simonw
Copy link
Author

simonw commented Aug 13, 2024

Looks like this is the cause of the bug:

class RegistrationForm(UserCreationForm):
"""
Form for registering a new user account.
Validates that the requested username is not already in use, and

That class inherits from django.contrib.auth.forms.UserCreationForm which now includes the new usable_password form field: https://github.com/django/django/blame/b99c608ea10cabc97a6b251cdb6e81ef2a83bdcf/django/contrib/auth/forms.py#L196-L203

@simonw
Copy link
Author

simonw commented Aug 13, 2024

I used this workaround in my own project for the moment:

diff --git a/core/views.py b/core/views.py
index 0c8991d..b7c8d40 100644
--- a/core/views.py
+++ b/core/views.py
@@ -15,6 +15,7 @@ from django.contrib.admin.views.decorators import staff_member_required
 from django.shortcuts import get_object_or_404, render
 from django.conf import settings
 from django.utils.safestring import mark_safe
+from django_registration.forms import RegistrationForm
 from django_registration.backends.activation.views import (
     RegistrationView as BaseRegistrationView,
 )
@@ -174,10 +175,15 @@ def homepage(request):
     return render(request, "homepage.html")
 
 
+class CustomRegisterForm(RegistrationForm):
+    usable_password = None
+
+
 class RegistrationView(BaseRegistrationView):
     template_name = "register.html"
     email_subject_template = "register_activation_email_subject.txt"
     email_body_template = "register_activation_email_body.txt"
+    form_class = CustomRegisterForm
 
     def get(self, request, *args, **kwargs):
         if request.user.is_authenticated:

@ubernostrum
Copy link
Owner

I'm already planning to give up on UserCreationForm for the next (5.1-compatible) release. Just need to find the time to actually rewrite the thing from scratch and in a way that doesn't randomly blow up at import time whenever someone uses a sufficiently-custom user model.

@ubernostrum
Copy link
Owner

Also I feel like probably the Django docs should be updated to clarify that UserCreationForm is now essentially an admin-only form class.

@ubernostrum ubernostrum pinned this issue Aug 13, 2024
@simonw
Copy link
Author

simonw commented Aug 13, 2024

I'm already planning to give up on UserCreationForm for the next (5.1-compatible) release. Just need to find the time to actually rewrite the thing from scratch and in a way that doesn't randomly blow up at import time whenever someone uses a sufficiently-custom user model.

That sounds good to me.

@simonw
Copy link
Author

simonw commented Aug 13, 2024

Also I feel like probably the Django docs should be updated to clarify that UserCreationForm is now essentially an admin-only form class.

Opened an issue for that here: https://code.djangoproject.com/ticket/35678

@ubernostrum
Copy link
Owner

ubernostrum commented Aug 14, 2024

@nessita
Copy link

nessita commented Aug 16, 2024

This is going to be fixed in Django main via django/django#18484 (and then backported to 5.1 since it's considered a release blocker). Thank you everyone for your contributions!

@ubernostrum
Copy link
Owner

WIP of removing django-registration's dependency on UserCreationForm is in this branch: https://github.com/ubernostrum/django-registration/tree/remove-usercreationform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants