Opened 12 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 (12)

comment:1 Changed 12 months ago by Tim Graham

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

comment:2 Changed 12 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 12 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 11 months ago by shangdahao

Owner: changed from nobody to shangdahao
Status: newassigned

comment:5 Changed 11 months ago by shangdahao

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

comment:6 Changed 10 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 9 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 9 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.

comment:9 Changed 5 months ago by Sławek Ehlert

Tim, I think the commit from this ticket doesn't properly support all the cases of custom user models (i.e. it assumes that the username field should be a subclass of CharField). I've opened #29449 for that. Also there's something weird going on with running the tests (details are in the ticket).

comment:10 Changed 4 months ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In f3fa86a:

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

This reverts commit 3333d935d2914cd80cf31f4803821ad5c0e2a51d due to
a crash if USERNAME_FIELD isn't a CharField.

comment:11 Changed 4 months ago by Tim Graham <timograham@…>

In 78f502c:

[2.1.x] Fixed #29449 -- Reverted "Fixed #28757 -- Allowed using contrib.auth forms without installing contrib.auth."

This reverts commit 3333d935d2914cd80cf31f4803821ad5c0e2a51d due to
a crash if USERNAME_FIELD isn't a CharField.

Backport of f3fa86a89b3b85242f49b2b9acf58b5ea35acc1f from master

comment:12 Changed 4 months ago by Tim Graham

Resolution: fixed
Status: closednew

I reverted the original patch due to the regression described in #29449. Unit tests for those cases are provided in PR 10020 which can be included in the patch for this ticket.

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