Opened 8 years ago
Closed 7 years 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: | 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__()
.
Attachments (1)
Change History (22)
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 |
comment:9 by , 8 years ago
Patch needs improvement: | set |
---|
comment:12 by , 8 years ago
Cc: | added |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:13 by , 7 years ago
Owner: | changed from | to
---|
comment:14 by , 7 years ago
Has patch: | unset |
---|---|
Patch needs improvement: | unset |
comment:16 by , 7 years ago
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 by , 7 years ago
Triage Stage: | Accepted → Ready for checkin |
---|---|
Version: | 1.10 → master |
comment:18 by , 7 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Ready for checkin → Accepted |
comment:19 by , 7 years ago
Patch needs improvement: | unset |
---|
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 .