#19845 closed Bug (invalid)
AUTH_USER_MODEL not accept sub application.
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Uncategorized | Version: | 1.5-rc-1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In settings.py to use a custom user AUTH_USER_MODEL i have to set the format app_label.model_name.
But my custom User model is within the following structure cadastro.pessoa.Usuario and django is not accepting.
Attachments (2)
Change History (10)
comment:1 by , 12 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 12 years ago
In my INSTALLED_APPS i have: "cadastro.pessoa"
If i set AUTH_USER_MODEL="cadastro.pessoa.Usuario" the exception is raised:
ImproperlyConfigured: AUTH_USER_MODEL must be of the form 'app_label.model_name'
If i set AUTH_USER_MODEL="pessoa.Usuario" the exception is raised:
ImproperlyConfigured: AUTH_USER_MODEL refers to model 'pessoa.Usuario' that has not been installed
comment:3 by , 12 years ago
I suspect something's wrong with your model definition. Can you upload cadastro/pessoa/models.py?
follow-up: 5 comment:4 by , 12 years ago
I was receiving the following validation error when running django-admin.py validate
:
ImproperlyConfigured: AUTH_USER_MODEL refers to model 'account.CustomUser' that has not been installed
The culprit was an ImportError
in my account.models
file.
follow-up: 6 comment:5 by , 12 years ago
Replying to matt@…:
I was receiving the following validation error when running
django-admin.py validate
:
ImproperlyConfigured: AUTH_USER_MODEL refers to model 'account.CustomUser' that has not been installed
The culprit was an
ImportError
in myaccount.models
file.
Excuse me, but beyond a ImportError, does that mean?
comment:6 by , 12 years ago
Replying to eltonplima@…:
I have now discovered the true source of my problem. My models.py
file was importing some custom functions from a separate file. This file was also calling the django.contrib.auth.get_user_model
function. If you call that function before your custom user model has been installed, it will raise an ImproperlyConfigured
exception.
The two error messages mentioned in comment#2 are both included as part of the django.contrib.auth.get_user_model
function. You might want to check through your code, ensuring that your custom user models.py
file is not importing anything that calls that function.
comment:7 by , 11 years ago
Resolution: | invalid |
---|---|
Status: | closed → new |
Type: | Uncategorized → Bug |
I'm running into this same issue, but I believe it is a bug in the code. Here is the relevant line:
app_label, model_name = settings.AUTH_USER_MODEL.split('.')
This is a problem, if for example, your AUTH_USER_MODEL looks like this:
AUTH_USER_MODEL = "apps.accounts.UserAccount"
split()
will return a three-element list and raise an "ValueError: too many values to unpack", triggering the exception.
I've copied the function below and linked to the line on github.
https://github.com/django/django/blob/master/django/contrib/auth/__init__.py#L117
def get_user_model(): """ Returns the User model that is active in this project. """ from django.db.models import get_model try: app_label, model_name = settings.AUTH_USER_MODEL.split('.') except ValueError: raise ImproperlyConfigured("AUTH_USER_MODEL must be of the form 'app_label.model_name'") user_model = get_model(app_label, model_name) if user_model is None: raise ImproperlyConfigured("AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL) return user_model
comment:8 by , 11 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
No, this is *not* an error in Django; it's an error in your code.
AUTH_USER_MODEL *is not* a dotted module include path. It's an "app name.model name" definition, the same as you would get in a fixture file.
AUTH_USER_MODEL = "apps.accounts.UserAccount" is an invalid value.
The app label is the last part of the dotted path to the app. It's the usual convention in Django.