Django-filter: Apps aren't loaded yet

Created on 20 Oct 2016  路  5Comments  路  Source: carltongibson/django-filter

I'm running django 1.10.2, django-filter 0.15.3, and djangorestframework 3.5.0 on python 2.7.11. When I add django-filter to my installed apps I now get this when i try and start the server.

Unhandled exception in thread started by <function wrapper at 0x10e3e5c80>
Traceback (most recent call last):
  File "/.jdev/python/.virtualenvs/anton/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/.jdev/python/.virtualenvs/anton/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 113, in inner_run
    autoreload.raise_last_exception()
  File "/.jdev/python/.virtualenvs/anton/lib/python2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
    six.reraise(*_exception)
  File "/.jdev/python/.virtualenvs/anton/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/.jdev/python/.virtualenvs/anton/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/.jdev/python/.virtualenvs/anton/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/.jdev/python/.virtualenvs/anton/lib/python2.7/site-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/.jdev/python/.virtualenvs/anton/lib/python2.7/site-packages/django_filters/__init__.py", line 3, in <module>
    from .filterset import FilterSet
  File "/.jdev/python/.virtualenvs/anton/lib/python2.7/site-packages/django_filters/filterset.py", line 16, in <module>
    from .compat import remote_field, remote_queryset
  File "/.jdev/python/.virtualenvs/anton/lib/python2.7/site-packages/django_filters/compat.py", line 19, in <module>
    from rest_framework.compat import coreapi
  File "/.jdev/python/.virtualenvs/anton/lib/python2.7/site-packages/rest_framework/compat.py", line 210, in <module>
    import guardian.shortcuts  # Fixes #1624
  File "/.jdev/python/.virtualenvs/anton/lib/python2.7/site-packages/guardian/shortcuts.py", line 6, in <module>
    from django.contrib.auth.models import Group, Permission
  File "/.jdev/python/.virtualenvs/anton/lib/python2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/.jdev/python/.virtualenvs/anton/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
    class AbstractBaseUser(models.Model):
  File "/.jdev/python/.virtualenvs/anton/lib/python2.7/site-packages/django/db/models/base.py", line 105, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/.jdev/python/.virtualenvs/anton/lib/python2.7/site-packages/django/apps/registry.py", line 237, in get_containing_app_config
    self.check_apps_ready()
  File "/.jdev/python/.virtualenvs/anton/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

Most helpful comment

The interaction only occurs with DRF+django-filter+django-guardian, which is why it doesn't show up in the test suite (no compatibility w/ django-guardian since it's not really relevant).

The relevant portion of the trace is this:

  File "lib/python2.7/site-packages/django_filters/compat.py", line 19, in <module>
    from rest_framework.compat import coreapi
  File "lib/python2.7/site-packages/rest_framework/compat.py", line 210, in <module>
    import guardian.shortcuts  # Fixes #1624
  File "lib/python2.7/site-packages/guardian/shortcuts.py", line 6, in <module>
    from django.contrib.auth.models import Group, Permission

I've submitted #526, which should fix the issue, but I'm not sure if this is also something that should be fixed in DRF or django-guardian.

All 5 comments

Do you can provide contents of INSTALLED_APPS?

I sure ca. @ad-m

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'rest_framework',
    'django_filters',
    'corsheaders',
    'guardian',

    'model_monitoring',
    'deck_builder',
]

btw - it's not actually necessary to add django-filter to INSTALLED_APPS.

There are no templates, static files, models, autodiscoverable modules, etc...


Edit: This was true at the time. This is no longer true.

The interaction only occurs with DRF+django-filter+django-guardian, which is why it doesn't show up in the test suite (no compatibility w/ django-guardian since it's not really relevant).

The relevant portion of the trace is this:

  File "lib/python2.7/site-packages/django_filters/compat.py", line 19, in <module>
    from rest_framework.compat import coreapi
  File "lib/python2.7/site-packages/rest_framework/compat.py", line 210, in <module>
    import guardian.shortcuts  # Fixes #1624
  File "lib/python2.7/site-packages/guardian/shortcuts.py", line 6, in <module>
    from django.contrib.auth.models import Group, Permission

I've submitted #526, which should fix the issue, but I'm not sure if this is also something that should be fixed in DRF or django-guardian.

@rpkilby thanks so much. I had no idea that I didn't need to add it since the examples showed it like that. I have everything working fine now

Was this page helpful?
0 / 5 - 0 ratings