RequiredPermissionMixin requires loaded apps?

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/", line 6, in <module>
    from medux.common.api import MeduxPluginAppConfig
  File "/home/christian/Projekte/medux-common/src/medux/common/api/", line 1, in <module>
    from .interfaces import MeduxPluginAppConfig
  File "/home/christian/Projekte/medux-common/src/medux/common/api/", line 7, in <module>
    from django.contrib.auth.mixins import PermissionRequiredMixin
  File "/.../.venv/lib/python3.10/site-packages/django/contrib/auth/", line 5, in <module>
    from django.contrib.auth.views import redirect_to_login
  File "/.../.venv/lib/python3.10/site-packages/django/contrib/auth/", line 12, in <module>
    from django.contrib.auth.forms import (
  File "/.../.venv/lib/python3.10/site-packages/django/contrib/auth/", line 6, in <module>
    from django.contrib.auth.models import User
  File "/.../.venv/lib/python3.10/site-packages/django/contrib/auth/", line 3, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/.../.venv/lib/python3.10/site-packages/django/contrib/auth/", line 49, in <module>
    class AbstractBaseUser(models.Model):
  File "/.../.venv/lib/python3.10/site-packages/django/db/models/", line 127, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/.../.venv/lib/python3.10/site-packages/django/apps/", line 260, in get_containing_app_config
  File "/.../.venv/lib/python3.10/site-packages/django/apps/", 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.

What version of Django are you using?

You could try using the python -v parameter to get a trace of all the imports as they occur - it might provide some additional useful information

What command are you running that generates this output? Have you tried something else like shell or check?

(Note: I tried browsing your source code. I see a number of references to a medux.common package, but don’t see any such module in that repo.)

Sorry, I wasn’t able to add the link to the medux-common package because as newcomer in the forum I am only allowed to post 2 links :wink: and after I wanted to edit the message and “describe” the link to medux-common, I was banned by Akismet :wink:
But all good now, medux-common is here.

I am using Django 4.1.6, Python 3.10. Output is from ./ runserver'. shellandcheck` produce same output.
Don’t be too strict finding other oddities in my code - it may not be the best one, lots of fuzzy work and revolving there yet.
But this one’s a mystery.

Just another thing: you will recognize the@Interface decorator - this is part of the GDAPS plugin system and registers this class as plugin at declaration time using a meta class. But I think this has nothing to do with it.

Side note: Don’t worry about the Akismet warnings. They send a notice to the moderators, and usually the moderators will read and approve those warnings within a day.

Already done, else I couldn’t write here now :wink: