AppRegistryNotReady caused by __init__.py
jayvdb opened this issue · 0 comments
jayvdb commented
The easy fix is to not import everything into __init__
, but that changes the API. The bad solution is to tell people to not list the app in INSTALLED_APPS. The ugly solution is to change views.py
to import DRF internals inside the methods where they are needed, not importing at the top.
python3 manage.py migrate
...
File "/usr/lib/python3.8/site-packages/rest_flex_fields/__init__.py", line 3, in <module>
from .views import FlexFieldsModelViewSet
File "/usr/lib/python3.8/site-packages/rest_flex_fields/views.py", line 6, in <module>
from rest_framework import viewsets
File "/usr/lib/python3.8/site-packages/rest_framework/viewsets.py", line 27, in <module>
from rest_framework import generics, mixins, views
File "/usr/lib/python3.8/site-packages/rest_framework/generics.py", line 9, in <module>
from rest_framework import mixins, views
File "/usr/lib/python3.8/site-packages/rest_framework/views.py", line 17, in <module>
from rest_framework.schemas import DefaultSchema
File "/usr/lib/python3.8/site-packages/rest_framework/schemas/__init__.py", line 33, in <module>
authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
File "/usr/lib/python3.8/site-packages/rest_framework/settings.py", line 220, in __getattr__
val = perform_import(val, attr)
File "/usr/lib/python3.8/site-packages/rest_framework/settings.py", line 168, in perform_import
return [import_from_string(item, setting_name) for item in val]
File "/usr/lib/python3.8/site-packages/rest_framework/settings.py", line 168, in <listcomp>
return [import_from_string(item, setting_name) for item in val]
File "/usr/lib/python3.8/site-packages/rest_framework/settings.py", line 177, in import_from_string
return import_string(val)
File "/usr/lib/python3.8/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "/usr/lib64/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/usr/lib/python3.8/site-packages/rest_framework_jwt/authentication.py", line 17, in <module>
from rest_framework_jwt.blacklist.exceptions import (
File "/usr/lib/python3.8/site-packages/rest_framework_jwt/blacklist/exceptions.py", line 8, in <module>
class MissingToken(AuthenticationFailed):
File "/usr/lib/python3.8/site-packages/rest_framework_jwt/blacklist/exceptions.py", line 10, in MissingToken
msg = _('The token is missing.')
File "/usr/lib/python3.8/site-packages/django/utils/translation/__init__.py", line 105, in ugettext
return gettext(message)
File "/usr/lib/python3.8/site-packages/django/utils/translation/__init__.py", line 92, in gettext
return _trans.gettext(message)
File "/usr/lib/python3.8/site-packages/django/utils/translation/trans_real.py", line 354, in gettext
_default = _default or translation(settings.LANGUAGE_CODE)
File "/usr/lib/python3.8/site-packages/django/utils/translation/trans_real.py", line 267, in translation
_translations[language] = DjangoTranslation(language)
File "/usr/lib/python3.8/site-packages/django/utils/translation/trans_real.py", line 154, in __init__
self._add_installed_apps_translations()
File "/usr/lib/python3.8/site-packages/django/utils/translation/trans_real.py", line 195, in _add_installed_apps_translations
raise AppRegistryNotReady(
django.core.exceptions.AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.
Also occurs with drf_extended_viewset and beda-software/drf-writable-nested#93