Opened 7 months ago

Last modified 4 months ago

#28757 new Cleanup/optimization

Allow using forms of contrib.auth without installing contrib.auth

Reported by: Sagar Chalise Owned by: shangdahao
Component: contrib.auth Version: 1.11
Severity: Normal Keywords: auth forms apps
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It seems the forms available in contrib.auth app cannot be used without using contrib.auth in settings.INSTALLED_APPS.
May be break some of reusable feature of forms into base_forms.py just like AbstractBaseUser model.

Change History (8)

comment:1 Changed 7 months ago by Tim Graham

Which forms are you trying to use and what error do you get?

comment:2 Changed 7 months ago by Sagar Chalise

Basically, I am using custom user model which avoids both groups and permissions. I could easily use Authentication as well as Password related forms but seems the forms.py directly imports User from contrib.auth.models https://github.com/django/django/blob/master/django/contrib/auth/forms.py#L10. Which seems to enforce me to install contrib.auth package.

comment:3 Changed 7 months ago by Tim Graham

Summary: Using forms of contrib.auth without installing contrib.authAllow using forms of contrib.auth without installing contrib.auth
Triage Stage: UnreviewedAccepted
Type: New featureCleanup/optimization

I wonder if moving that import inside the form class where it's used would be feasible and solve the issue.

comment:4 Changed 6 months ago by shangdahao

Owner: changed from nobody to shangdahao
Status: newassigned

comment:5 Changed 6 months ago by shangdahao

Has patch: set
Last edited 6 months ago by shangdahao (previous) (diff)

comment:6 Changed 5 months ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 3333d93:

Fixed #28757 -- Allowed using contrib.auth forms without installing contrib.auth.

Also fixed #28608 -- Allowed UserCreationForm and UserChangeForm to
work with custom user models.

Thanks Sagar Chalise and Rômulo Collopy for reports, and Tim Graham
and Tim Martin for reviews.

comment:7 Changed 4 months ago by Tim Graham

Has patch: unset
Resolution: fixed
Status: closednew

After this commit, there are some errors when running $ ./tests/runtests.py auth_tests.test_management (but adding --reverse fixes it). shangdahao, can you debug that?

comment:8 Changed 4 months ago by Tim Graham

I tried to solve the issue by putting the reload of django.contrib.auth.forms in django.test.signals.user_model_swapped() rather than limiting it to the Django tests. I couldn't get it to work.

The issue is solved by adding import django.contrib.auth.forms to the top of auth_tests/test_management.py but I don't know why that works.

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