Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#19845 closed Bug (invalid)

AUTH_USER_MODEL not accept sub application.

Reported by: eltonplima@… 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)

models.py (12.1 KB ) - added by eltonplima@… 12 years ago.
The models.py
models.2.py (10.3 KB ) - added by eltonplima@… 12 years ago.
I've sent the wrong file.

Download all attachments as: .zip

Change History (10)

comment:1 by Aymeric Augustin, 12 years ago

Resolution: invalid
Status: newclosed

The app label is the last part of the dotted path to the app. It's the usual convention in Django.

comment:2 by anonymous, 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 Aymeric Augustin, 12 years ago

I suspect something's wrong with your model definition. Can you upload cadastro/pessoa/models.py?

by eltonplima@…, 12 years ago

Attachment: models.py added

The models.py

by eltonplima@…, 12 years ago

Attachment: models.2.py added

I've sent the wrong file.

comment:4 by matt@…, 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.

in reply to:  4 ; comment:5 by eltonplima@…, 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 my account.models file.

Excuse me, but beyond a ImportError, does that mean?

in reply to:  5 comment:6 by matt@…, 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 esoergel@…, 11 years ago

Resolution: invalid
Status: closednew
Type: UncategorizedBug

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 Russell Keith-Magee, 11 years ago

Resolution: invalid
Status: newclosed

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.

Last edited 11 years ago by Russell Keith-Magee (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top