Opened 6 years ago

Closed 6 years ago

#29780 closed Cleanup/optimization (duplicate)

Using default UserModel in django.contrib.auth forms

Reported by: Marcelo Canina Owned by:
Component: contrib.auth Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

In django.contrib.auth.forms.py we have the

UserModel = get_user_model()

but User model is used twice in: UserCreationForm and UserChangeForm in theirs meta

class UserChangeForm(forms.ModelForm):
    class Meta: 
        model = User

I think above forms should use UserModel instead of User so there is no need to subclass them to use project's user model when using a custom User model.

Change History (6)

comment:1 by Javier Buzzi, 6 years ago

Created this PR really quickly to see if it passes all tests on the first go. https://github.com/django/django/pull/10424

comment:2 by Javier Buzzi, 6 years ago

Looks like the tests all passed. I have an issue with it though, how to really test this? By the time the tests run the UserChangeForm has already been executed and the metaclass already did its thing so no matter how much you change the AUTH_USER_MODEL nothing will change; I thought about making get_user_model() lazy.. but that could introduce further complications. I suppose thats why this was like this to begin with. Can anyone shed some light?

Last edited 6 years ago by Javier Buzzi (previous) (diff)

comment:3 by Can Sarıgöl, 6 years ago

Owner: changed from nobody to Can Sarıgöl
Status: newassigned

comment:4 by Can Sarıgöl, 6 years ago

Owner: Can Sarıgöl removed
Status: assignednew

comment:5 by Javier Buzzi, 6 years ago

Needs tests: set
Version: 2.1master

comment:6 by Tim Graham, 6 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #28757. As you'll read about there, the issue isn't so simple.

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