#29780 closed Cleanup/optimization (duplicate)

Using default UserModel in django.contrib.auth forms

Reported by: Marcelo Canina Owned by:
Component: contrib.auth Version: master
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 Changed 10 months ago by Javier Buzzi

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 Changed 10 months ago by Javier Buzzi

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.

Version 0, edited 10 months ago by Javier Buzzi (next)

comment:3 Changed 10 months ago by Can Sarıgöl

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

comment:4 Changed 10 months ago by Can Sarıgöl

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

comment:5 Changed 10 months ago by Javier Buzzi

Needs tests: set
Version: 2.1master

comment:6 Changed 10 months ago by Tim Graham

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