django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
aboutofpluto opened this issue · 3 comments
Hi there,
I have this error message as soon as I add 'drf_writable_nested' to INSTALLED_APPS
.
** How to reproduce **
My environment is:
$ python --version
Python 3.7.3
$ pip freeze
...
Django==2.2.7
...
djangorestframework==3.10.3
...
drf-writable-nested==0.5.1
...
The problem occurs with the simplest possible installation:
- Start a new project
$ django-admin startproject testproject
- Edit settings.py to add drf and drf_writable_nested
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'drf_writable_nested',
]
- run server (or any command actually)
$ python manage.py runserver
....
File "/home/ab/work/django/venv-django-2.2.7/lib/python3.7/site-packages/drf_writable_nested/__init__.py", line 11, in <module>
from .mixins import NestedUpdateMixin, NestedCreateMixin, UniqueFieldsMixin
File "/home/ab/work/django/venv-django-2.2.7/lib/python3.7/site-packages/drf_writable_nested/mixins.py", line 4, in <module>
from django.contrib.contenttypes.fields import GenericRelation
File "/home/ab/work/django/venv-django-2.2.7/lib/python3.7/site-packages/django/contrib/contenttypes/fields.py", line 3, in <module>
from django.contrib.contenttypes.models import ContentType
File "/home/ab/work/django/venv-django-2.2.7/lib/python3.7/site-packages/django/contrib/contenttypes/models.py", line 133, in <module>
class ContentType(models.Model):
File "/home/ab/work/django/venv-django-2.2.7/lib/python3.7/site-packages/django/db/models/base.py", line 103, in __new__
app_config = apps.get_containing_app_config(module)
File "/home/ab/work/django/venv-django-2.2.7/lib/python3.7/site-packages/django/apps/registry.py", line 252, in get_containing_app_config
self.check_apps_ready()
File "/home/ab/work/django/venv-django-2.2.7/lib/python3.7/site-packages/django/apps/registry.py", line 135, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
** Possible fix **
This can be solved by removing the import
statements from drf_writable_nested/__init__.py
This fix is logical (to me at least) and simply implies to import from serializers
:
from drf_writable_nested.serializers import WritableNestedModelSerializer
If you think the fix is valid, I'll create a pull request.
Best regards,
ab
Hello @aboutofpluto. Thank you for your contribution. There is another opened issue about fixing the tests for Django 2.2 (#87). Your fix will break backward compatibility. If you have ideas about how to fix it in another way - welcome
I am also having this issue.
@aboutofpluto Looks like this patch is a graceful solve that won't break backward compatibility.
@ruscoder can we get it merged?
@aboutofpluto @jqsjqs
The simplest solution is not to add 'drf_writable_nested' to installed_apps - it is not necessary for the package.