Opened 6 years ago

Last modified 5 weeks 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: Ülgen Sarıkavak 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 (13)

comment:1 by Tim Graham, 6 years ago

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

comment:2 by Sagar Chalise, 6 years ago

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 by Tim Graham, 6 years ago

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 by shangdahao, 6 years ago

Owner: changed from nobody to shangdahao
Status: newassigned

comment:5 by shangdahao, 6 years ago

Has patch: set
Version 0, edited 6 years ago by shangdahao (next)

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

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 by Tim Graham, 6 years ago

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 by Tim Graham, 6 years ago

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 by Sławek Ehlert, 6 years ago

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

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

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 by Tim Graham, 6 years ago

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.

comment:13 by Ülgen Sarıkavak, 5 weeks ago

Cc: Ülgen Sarıkavak added
Note: See TracTickets for help on using tickets.
Back to Top