Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#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 alasdair, 11 years ago

Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

The warning for the INSTALLED_APPS setting covers this.

> App names must be unique

The application names (that is, the final dotted part of the path to the module containing models.py) defined in INSTALLED_APPS must be unique. For example, you can’t include both django.contrib.auth and myproject.auth in INSTALLED_APPS.

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.

Version 0, edited 11 years ago by alasdair (next)

comment:2 by alasdair, 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 Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 317fd13c7ac25db94d3dabf8ee115acbfbd3e5a7:

Fixed #21562 -- Warned against using the same app name as a django contrib app.

Thanks yourcelf for the report.

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

In 4f9590836ca679e4aef2627a71f4277ca4c80605:

[1.6.x] Fixed #21562 -- Warned against using the same app name as a django contrib app.

Thanks yourcelf for the report.

Backport of 317fd13c7a from master

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