Opened 8 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 )
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 , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 8 years ago
Has patch: | set |
---|
by , 8 years ago
comment:3 by , 8 years ago
Summary: | admin login action is maxlength 254 rether thet 150 characters → admin login action is maxlength 254 rather than 150 characters |
---|
comment:4 by , 8 years ago
comment:5 by , 8 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 , 8 years ago
Component: | Forms → contrib.auth |
---|---|
Has patch: | unset |
Resolution: | → invalid |
Status: | assigned → closed |
Summary: | admin login action is maxlength 254 rather than 150 characters → Make AuthenticationForm use the username length from the user model |
Triage Stage: | Unreviewed → Accepted |
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 , 8 years ago
Description: | modified (diff) |
---|---|
Resolution: | invalid |
Status: | closed → new |
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 .