Opened 12 months ago

Closed 4 weeks ago

#27515 closed Cleanup/optimization (fixed)

Make AuthenticationForm use the username length from the user model

Reported by: Ramin Farajpour Cami Owned by: Lucas Connors
Component: contrib.auth Version: master
Severity: Normal Keywords:
Cc: Andrey Kuzminov Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

AuthenticationForm has a hardcoded max_length=254 (#19130). It might be able to use the max length from the user model with something like: self.fields['username'].max_length = UserModel._meta.get_field(UserModel.USERNAME_FIELD).max_length in AuthenticationForm.__init__().

Attachments (1)

fix.patch (452 bytes) - added by Ramin Farajpour Cami 12 months ago.

Download all attachments as: .zip

Change History (22)

comment:1 Changed 12 months ago by Ramin Farajpour Cami

Owner: changed from nobody to Ramin Farajpour Cami
Status: newassigned

comment:2 Changed 12 months ago by Ramin Farajpour Cami

Has patch: set

Changed 12 months ago by Ramin Farajpour Cami

Attachment: fix.patch added

comment:3 Changed 12 months ago by Ramin Farajpour Cami

Summary: admin login action is maxlength 254 rether thet 150 charactersadmin login action is maxlength 254 rather than 150 characters

comment:4 Changed 12 months ago by Tim Graham

The suggestion doesn't account for custom user models and undoes #19130 (you might try using git blame to investigate history next time).

If the current situation is problematic for you, perhaps there would be some value in setting the max length based on the custom user model as Claude suggested .

comment:5 Changed 12 months ago by Ramin Farajpour Cami

User model use max_length=150,also in add user form set 150,
What your means "value setting the max length based on the custom user model"?

comment:6 Changed 12 months ago by Tim Graham

Component: Formscontrib.auth
Has patch: unset
Resolution: invalid
Status: assignedclosed
Summary: admin login action is maxlength 254 rather than 150 charactersMake AuthenticationForm use the username length from the user model
Triage Stage: UnreviewedAccepted

Custom user models may have a username with length other than 150, that's why using that value isn't appropriate. We might be able to use that with something like this: self.fields['username'].max_length = UserModel._meta.get_field(UserModel.USERNAME_FIELD).max_length.

comment:7 Changed 12 months ago by Tim Graham

Description: modified (diff)
Resolution: invalid
Status: closednew

comment:8 Changed 12 months ago by Ramin Farajpour Cami

Has patch: set

comment:9 Changed 12 months ago by Tim Graham

Patch needs improvement: set

comment:10 Changed 11 months ago by Andrey Kuzminov

Can I take this ticket or is it still Ramin's?

comment:11 Changed 11 months ago by Ramin Farajpour Cami

Yes, please assign to you

comment:12 Changed 11 months ago by Andrey Kuzminov

Cc: Andrey Kuzminov added
Owner: changed from Ramin Farajpour Cami to Andrey Kuzminov
Status: newassigned

comment:13 Changed 3 months ago by Lucas Connors

Owner: changed from Andrey Kuzminov to Lucas Connors

comment:14 Changed 3 months ago by Lucas Connors

Has patch: unset
Patch needs improvement: unset

comment:15 Changed 3 months ago by Lucas Connors

Has patch: set
Last edited 3 months ago by Tim Graham (previous) (diff)

comment:16 Changed 3 months ago by Lucas Connors

Sorry for the spam. I thought unchecking and rechecking would automatically find the PR on Github. This is it here:
https://github.com/django/django/pull/8925

comment:17 Changed 3 months ago by felixxm

Triage Stage: AcceptedReady for checkin
Version: 1.10master

comment:18 Changed 3 months ago by Tim Graham

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

comment:19 Changed 6 weeks ago by felixxm

Patch needs improvement: unset

comment:20 Changed 4 weeks ago by Tim Graham <timograham@…>

In d2333912:

Refs #19130 -- Added a test for AuthenticationForm.username max_length.

This will be a more useful regression test after refs #27515.

comment:21 Changed 4 weeks ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 5ceaf146:

Fixed #27515 -- Made AuthenticationForm's username field use the max_length from the model field.

Thanks Ramin Farajpour Cami for the report.

Note: See TracTickets for help on using tickets.
Back to Top