Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_application_model incompatible with Django 1.7 #151

Closed
edemocracy opened this issue Sep 11, 2014 · 3 comments
Closed

get_application_model incompatible with Django 1.7 #151

edemocracy opened this issue Sep 11, 2014 · 3 comments
Milestone

Comments

@edemocracy
Copy link

get_application_model works fine with Django 1.6.5, but fails with 1.7.
Application = get_application_model() is executed at the top level of the application's model.py

Traceback (most recent call last):
  File "manage.py", line 12, in <module>
    execute_from_command_line(sys.argv)
  File "<pythonpath>/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "<pythonpath>/site-packages/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "<pythonpath>/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "<pythonpath>/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "<pythonpath>/site-packages/django/apps/config.py", line 197, in import_models
    self.models_module = import_module(models_module_name)
  File "<pythonpath>/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "<projpath>/myapp/models.py", line 35, in <module>
    Application = get_application_model()
  File "<pythonpath>/site-packages/oauth2_provider/models.py", line 241, in get_application_model
    app_model = get_model(app_label, model_name)
  File "<pythonpath>/site-packages/django/apps/registry.py", line 199, in get_model
    self.check_models_ready()
  File "<pythonpath>/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.
@edemocracy
Copy link
Author

I've found this workaround:

from oauth2_provider.settings import oauth2_settings
APPLICATION_MODEL = oauth2_settings.APPLICATION_MODEL

and replace all

field = models.ForeignKey(Application,...)

with

field = models.ForeignKey(APPLICATION_MODEL,...)

@masci
Copy link
Contributor

masci commented Mar 26, 2015

@edemocracy could you provide a snippet of code causing the error?

@maurizio-mariani
Copy link

Still this bug in django>=1.9.1
This happens when try to use get_application_model() as foreign key
models.ForeignKey(get_application_model(), null=True, blank=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants