I got a Django project with some views that inherit from a mixin class. That class itself is a GDAPS interface (my own plugin system), but that shouldn’t matter. Many of the views should be restricted to some permissions, so I decided to let the “interface” mixin class inherit from RequiredPermissionMixin.
But as soon as I added this parent, Django crashed and told me that my apps are not loaded. I know generally what that means, but couldn’t find the error. I first posted the issue on django-development, as I supposed being django.contrib.auth the culprit because it imports redirect_to_login globally, and uses it in just one method. After moving the import statement
from django.contrib.auth.views import redirect_to_login
to the local method, everything worked again (as expected).
But that doesn’t seem the problem, as Simon (a Django dev) told me.
Here’s a trace:
...
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/home/christian/Projekte/medux/src/medux/core/apps.py", line 6, in <module>
from medux.common.api import MeduxPluginAppConfig
File "/home/christian/Projekte/medux-common/src/medux/common/api/__init__.py", line 1, in <module>
from .interfaces import MeduxPluginAppConfig
File "/home/christian/Projekte/medux-common/src/medux/common/api/interfaces.py", line 7, in <module>
from django.contrib.auth.mixins import PermissionRequiredMixin
File "/.../.venv/lib/python3.10/site-packages/django/contrib/auth/mixins.py", line 5, in <module>
from django.contrib.auth.views import redirect_to_login
File "/.../.venv/lib/python3.10/site-packages/django/contrib/auth/views.py", line 12, in <module>
from django.contrib.auth.forms import (
File "/.../.venv/lib/python3.10/site-packages/django/contrib/auth/forms.py", line 6, in <module>
from django.contrib.auth.models import User
File "/.../.venv/lib/python3.10/site-packages/django/contrib/auth/models.py", line 3, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/.../.venv/lib/python3.10/site-packages/django/contrib/auth/base_user.py", line 49, in <module>
class AbstractBaseUser(models.Model):
File "/.../.venv/lib/python3.10/site-packages/django/db/models/base.py", line 127, in __new__
app_config = apps.get_containing_app_config(module)
File "/.../.venv/lib/python3.10/site-packages/django/apps/registry.py", line 260, in get_containing_app_config
self.check_apps_ready()
File "/.../.venv/lib/python3.10/site-packages/django/apps/registry.py", line 138, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Has anyone a hint why this happens? I can’t really find the circular import.
Code is open source at Medux
Any hints appreciated.