Alir3z4/django-cuser

cuser import fails in Django 1.7

Closed this issue · 3 comments

Hi,
the following vanilla installation works with Django 1.6 but not with Django 1.7:
#1# settings.py

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'cuser',
    'test_dj17',
)
MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'cuser.middleware.CuserMiddleware',
)

#2# test_dj17/models.py

from django.db import models
from cuser.middleware import CuserMiddleware
from cuser.fields import CurrentUserField
# Create your models here.

In Django 1.6 everything works fine, in Django 1.7 I get:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/srv/vhost73/virtual/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/srv/vhost73/virtual/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "/srv/vhost73/virtual/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/srv/vhost73/virtual/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/srv/vhost73/virtual/local/lib/python2.7/site-packages/django/apps/config.py", line 197, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/srv/vhost73/project/test_dj17/models.py", line 3, in <module>
    from cuser.middleware import CuserMiddleware
  File "/srv/vhost73/virtual/local/lib/python2.7/site-packages/cuser/middleware.py", line 5, in <module>
    User = get_user_model()
  File "/srv/vhost73/virtual/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 136, in get_user_model
    return django_apps.get_model(settings.AUTH_USER_MODEL)
  File "/srv/vhost73/virtual/local/lib/python2.7/site-packages/django/apps/registry.py", line 199, in get_model
    self.check_models_ready()
  File "/srv/vhost73/virtual/local/lib/python2.7/site-packages/django/apps/registry.py", line 131, in check_models_ready
    raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

Am I missing something in my configuration or is the problem due to changes in 1.7? The 1.7 documentation says: " get_user_model() only works once Django has imported all models." (https://docs.djangoproject.com/en/1.7/topics/auth/customizing/).

Best wishes,
Volker

@VoNov Thanks for traceback and report this issue, I'll look into the issue to resolve it soon.

ps: I reformat you code snippet in your report, hope you don't mind ;)

@VoNov I fixed the error and issue new release: https://github.com/Alir3z4/django-cuser/releases/tag/2014.9.28

It's on pypi: https://pypi.python.org/pypi/django-cuser/2014.9.28
Here's the patch also #12
Please test the latest release and let me know about any issues.

Great - the patched version now works in my 1.7 installation. Thanks a lot!