11

I've been using [django-registration] (https://bitbucket.org/ubernostrum/django-registration) and now I have started using django 1.7b1 and here is the error I am getting the error copied below. It is being raised from django-registration in models.py:

try:
    from django.contrib.auth import get_user_model
    User = get_user_model()
except ImportError:
    from django.contrib.auth.models import User

and it seems it is being raised because get_user_model() is being called before the app registry is ready. I am not sure if this a compatibility issue or not, if yes is there a simple workaround for this? and if not can you help me identify what I am doing wrong?

RuntimeError: App registry isn't ready yet.
File "/Users/nima/pe-dev/manage.py", line 9, in <module>
  execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/core/management/__init__.py", line 427, in execute_from_command_line
  utility.execute()
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/core/management/__init__.py", line 391, in execute
  django.setup()
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/__init__.py", line 21, in setup
  apps.populate(settings.INSTALLED_APPS)
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/apps/registry.py", line 106, in populate
  app_config.import_models(all_models)
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/apps/config.py", line 190, in import_models
  self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
  __import__(name)
File "/Library/Python/2.7/site-packages/registration/models.py", line 15, in <module>
  User = get_user_model()
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/contrib/auth/__init__.py", line 136, in get_user_model
  return django_apps.get_model(settings.AUTH_USER_MODEL)
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/apps/registry.py", line 187, in get_model
  self.check_ready()
File "/Library/Python/2.7/site-packages/Django-1.7b1-py2.7.egg/django/apps/registry.py", line 119, in check_ready
  raise RuntimeError("App registry isn't ready yet.")
Nima
  • 3,129
  • 1
  • 21
  • 20

2 Answers2

25

Don't use the django-registration available from PyPI. It does not support Django 1.7 and it appears it never will. The repo maintainer has abdicated and the project appears unmaintained.

There is a maintenance fork available on Github which has worked well for me with Django 1.7:

https://github.com/macropin/django-registration

It's available from PyPI as django-registration-redux.

https://pypi.python.org/pypi/django-registration-redux/

You can install using pip:

pip install django-registration-redux

ptevans
  • 516
  • 5
  • 9
2

This note addresses your problem.

I think the preferred way to import User is:

from django.conf import settings
User = settings.AUTH_USER_MODEL

EDIT:

Looks like this problem has been noted but the project admin is being difficult about making the change. link. This is a bigger problem with the updates in Django 1.7.

I would say you could either: (1) fork the repo and make the change yourself, or (2) make the changes in your site packages folder after you pip install. The latter version won't work as well if you then push it to another server and install with requirements.txt. Note that if you do option 1 with requirements.txt, you'll want to point it to your repo rather than Django-registration.

Alex
  • 8,321
  • 1
  • 34
  • 30
  • That's exactly what I thought too. The problem tho is that I am not calling `get_user_model()` in my code at import time, it is being called in the [django-registration](https://bitbucket.org/ubernostrum/django-registration/src/8f242e35ef7c004e035e54b4bb093c32bf77c29f/registration/models.py?at=default#cl-15) application. So does this mean that django-registration is not compatible with 1.7b? – Nima Apr 14 '14 at 20:37
  • Yea seems like the repo owner is not maintaining it anymore which is a shame. I am not sure what the correct solution is here. I don't think `User = settings.AUTH_USER_MODEL` would do the job since `settings.AUTH_USER_MODEL` returns a string and using `get_model()` to get the actual model class is not possible here. – Nima Apr 14 '14 at 22:18
  • What if you just removed the get_user_model() part and imported the User? Currently looks like this: `try: from django.contrib.auth import get_user_model User = get_user_model() except ImportError: from django.contrib.auth.models import User` What if you delete the first four lines: `from django.contrib.auth.models import User` – Alex Apr 14 '14 at 23:48
  • 1
    Check out Russell's response [here](https://groups.google.com/forum/#!msg/django-developers/lmT1JxsWHPo/N2V9U5SN9gwJ). Looks like models can take string references to models. Thus the `settings.AUTH_USER_MODEL` should work. – Alex Apr 15 '14 at 00:34