#21562 closed Cleanup/optimization (fixed)
Bad things happen if you name your custom user app "auth"
Reported by: | Charlie DeTar | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It seems that odd conflicts and unexpected behavior happen if you create an app specifying a custom user model and name that app "auth"[1]. The general principle might also apply that bad things happen when you include two apps with the same ultimate module name (e.g. both "<foo>" and "django.contrib.<foo>", as well as any other dotted path to an app).
The documentation for reusable apps https://docs.djangoproject.com/en/dev/intro/reusable-apps/ mentions choosing app names that don't conflict with existing published apps for sharing convenience, but I can't find any mention of the fact that module names (even with differing dotted prefixes) should never collide for purposes of proper code function. Particularly with custom user models, where bare "auth" is a very natural thing to name your own implementation, this seems worth a mention.
[1] Specific problems: importing the model in the shell (e.g. "import auth.models.User") resulted in importing a "django.contrib.auth.models.User"; the post-syncdb signal for creating the first superuser followed the contract for creating a django.contrib User but put the results in a table made for the custom User, and trying to register the custom User resulted in an "already registered" error.
Change History (4)
comment:1 by , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Bug → Cleanup/optimization |
comment:2 by , 11 years ago
Has patch: | set |
---|
Pull request with suggested addition to the reusable apps tutorial: https://github.com/django/django/pull/2032
comment:3 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
The warning for the INSTALLED_APPS setting covers this.
I suggest we add a similar warning to the re-usable app tutorial. A reusable app shouldn't be named auth, messages, sites, or any other contrib name, or it's going to cause problems.