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 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 8 years ago.

Download all attachments as: .zip

Change History (22)

comment:1 by Ramin Farajpour Cami, 8 years ago

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

comment:2 by Ramin Farajpour Cami, 8 years ago

Has patch: set

by Ramin Farajpour Cami, 8 years ago

Attachment: fix.patch added

comment:3 by Ramin Farajpour Cami, 8 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, 8 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, 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 Tim Graham, 8 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, 8 years ago

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

comment:8 by Ramin Farajpour Cami, 8 years ago

Has patch: set

comment:9 by Tim Graham, 8 years ago

Patch needs improvement: set

comment:10 by Andrey Kuzminov, 8 years ago

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

comment:11 by Ramin Farajpour Cami, 8 years ago

Yes, please assign to you

comment:12 by Andrey Kuzminov, 8 years ago

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

comment:13 by Lucas Connors, 7 years ago

Owner: changed from Andrey Kuzminov to Lucas Connors

comment:14 by Lucas Connors, 7 years ago

Has patch: unset
Patch needs improvement: unset

comment:15 by Lucas Connors, 7 years ago

Has patch: set
Version 0, edited 7 years ago by Lucas Connors (next)

comment:16 by Lucas Connors, 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 Mariusz Felisiak, 7 years ago

Triage Stage: AcceptedReady for checkin
Version: 1.10master

comment:18 by Tim Graham, 7 years ago

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

comment:19 by Mariusz Felisiak, 7 years ago

Patch needs improvement: unset

comment:20 by Tim Graham <timograham@…>, 7 years ago

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

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