Opened 11 years ago

Closed 11 years ago

#21875 closed Bug (fixed)

Runtime Error with Django-Tastypie: "App registry isn't ready yet."

Reported by: benjamin.e.white1@… Owned by: nobody
Component: Documentation Version: 1.7-alpha-1
Severity: Normal Keywords: app-loading tastypie
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Including django-tastypie as installed app prevents me from running server, migrating, etc. I'm on Python 3.3.3

Traceback pasted below. Goes away when I remove django-tastypie as installed app.

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/benjaminwhite/django-trunk/django/core/management/__init__.py", line 427, in execute_from_command_line
    utility.execute()
  File "/Users/benjaminwhite/django-trunk/django/core/management/__init__.py", line 391, in execute
    django.setup()
  File "/Users/benjaminwhite/django-trunk/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/benjaminwhite/django-trunk/django/apps/registry.py", line 105, in populate
    app_config.import_models(all_models)
  File "/Users/benjaminwhite/django-trunk/django/apps/base.py", line 180, in import_models
    self.models_module = import_module(models_module_name)
  File "/Users/benjaminwhite/.virtualenvs/HUMAN_WRITES/lib/python3.3/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1022, in load_module
  File "<frozen importlib._bootstrap>", line 1003, in load_module
  File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 868, in _load_module
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  File "/Users/benjaminwhite/.virtualenvs/HUMAN_WRITES/lib/python3.3/site-packages/tastypie/models.py", line 32, in <module>
    from tastypie.compat import AUTH_USER_MODEL
  File "/Users/benjaminwhite/.virtualenvs/HUMAN_WRITES/lib/python3.3/site-packages/tastypie/compat.py", line 14, in <module>
    User = get_user_model()
  File "/Users/benjaminwhite/django-trunk/django/contrib/auth/__init__.py", line 133, in get_user_model
    user_model = apps.get_model(app_label, model_name)
  File "/Users/benjaminwhite/django-trunk/django/apps/registry.py", line 182, in get_model
    self.check_ready()
  File "/Users/benjaminwhite/django-trunk/django/apps/registry.py", line 118, in check_ready
    raise RuntimeError("App registry isn't ready yet.")
RuntimeError: App registry isn't ready yet.
(HUMAN_WRITES)Benjamins-MacBook-Air:narrativize benjaminwhite$ python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/benjaminwhite/django-trunk/django/core/management/__init__.py", line 427, in execute_from_command_line
    utility.execute()
  File "/Users/benjaminwhite/django-trunk/django/core/management/__init__.py", line 391, in execute
    django.setup()
  File "/Users/benjaminwhite/django-trunk/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/benjaminwhite/django-trunk/django/apps/registry.py", line 105, in populate
    app_config.import_models(all_models)
  File "/Users/benjaminwhite/django-trunk/django/apps/base.py", line 180, in import_models
    self.models_module = import_module(models_module_name)
  File "/Users/benjaminwhite/.virtualenvs/HUMAN_WRITES/lib/python3.3/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1022, in load_module
  File "<frozen importlib._bootstrap>", line 1003, in load_module
  File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 868, in _load_module
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  File "/Users/benjaminwhite/.virtualenvs/HUMAN_WRITES/lib/python3.3/site-packages/tastypie/models.py", line 32, in <module>
    from tastypie.compat import AUTH_USER_MODEL
  File "/Users/benjaminwhite/.virtualenvs/HUMAN_WRITES/lib/python3.3/site-packages/tastypie/compat.py", line 14, in <module>
    User = get_user_model()
  File "/Users/benjaminwhite/django-trunk/django/contrib/auth/__init__.py", line 133, in get_user_model
    user_model = apps.get_model(app_label, model_name)
  File "/Users/benjaminwhite/django-trunk/django/apps/registry.py", line 182, in get_model
    self.check_ready()
  File "/Users/benjaminwhite/django-trunk/django/apps/registry.py", line 118, in check_ready
    raise RuntimeError("App registry isn't ready yet.")
RuntimeError: App registry isn't ready yet.

Change History (5)

comment:1 by loic84, 11 years ago

Out of curiosity, does 'tastypie' appear before 'django.contrib.auth' in settings.INSTALLED_APPS?

Edit: Actually, looking at the code that's irrelevant. get_user_model() depends on apps.get_model() which is not available until the app registry is ready.

One way to fix it in django-tastypie would be to have tastypie.compat.AUTH_USER_MODEL be a string (settings.AUTH_USER_MODEL) on Django 1.7 (or even Django 1.5+).

Last edited 11 years ago by loic84 (previous) (diff)

comment:2 by Aymeric Augustin, 11 years ago

Component: UncategorizedDocumentation
Keywords: app-loading tastypie added; Django-Tastypie python3 removed
Triage Stage: UnreviewedAccepted

As implied here: https://docs.djangoproject.com/en/dev/topics/auth/customizing/#referencing-the-user-model the User module should be referenced by settings.AUTH_USER_MODEL at import time. get_user_model() doesn't work until the initialization sequence is complete.

We could clarify this section of the docs again, and also say something in the release notes. But the fix belongs to tastypie.

comment:4 by Aymeric Augustin, 11 years ago

Has patch: set

comment:5 by Aymeric Augustin <aymeric.augustin@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 1be31c320c2e0efa1730f73509d64e024ab31a0c:

Fixed #21875 -- Clarified that get_user_model() only works at run time.

Thanks Benjamin White for the report.

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