Opened 7 years ago

Last modified 7 years ago

#27515 closed Cleanup/optimization

Make AuthenticationForm use the username length from the user model — at Version 7

Reported by: Ramin Farajpour Cami Owned by: Ramin Farajpour Cami
Component: contrib.auth Version: dev
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__().

Change History (8)

comment:1 by Ramin Farajpour Cami, 7 years ago

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

comment:2 by Ramin Farajpour Cami, 7 years ago

Has patch: set

by Ramin Farajpour Cami, 7 years ago

Attachment: fix.patch added

comment:3 by Ramin Farajpour Cami, 7 years ago

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

comment:4 by Tim Graham, 7 years ago

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 by Ramin Farajpour Cami, 7 years ago

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 by Tim Graham, 7 years ago

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 by Tim Graham, 7 years ago

Description: modified (diff)
Resolution: invalid
Status: closednew
Note: See TracTickets for help on using tickets.
Back to Top