question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Daphne 3.0.1 Apps aren't loaded yet.

See original GitHub issue

Hello I’m facing this issue on daphne 3.0.1 :

` ● daphne.service - daphne daemon Loaded: loaded (/etc/systemd/system/daphne.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Tue 2020-11-24 15:13:06 UTC; 5s ago Process: 3125951 ExecStart=/usr/local/bin/daphne -u /home/git/demo_API/www/demo_ws.sock demo_API.asgi:application -v 1 --access-log /home/git/demo_API/www/logs/debug.log (code=exited, status=1/FAILURE) Main PID: 3125951 (code=exited, status=1/FAILURE)

Nov 24 15:13:06 ubuntu daphne[3125951]: class AbstractBaseUser(models.Model): Nov 24 15:13:06 ubuntu daphne[3125951]: File “/home/git/.local/lib/python3.8/site-packages/django/db/models/base.py”, line 108, in __ new __ Nov 24 15:13:06 ubuntu daphne[3125951]: app_config = apps.get_containing_app_config(module) Nov 24 15:13:06 ubuntu daphne[3125951]: File “/home/git/.local/lib/python3.8/site-packages/django/apps/registry.py”, line 253, in get_containing_app_config Nov 24 15:13:06 ubuntu daphne[3125951]: self.check_apps_ready() Nov 24 15:13:06 ubuntu daphne[3125951]: File “/home/git/.local/lib/python3.8/site-packages/django/apps/registry.py”, line 136, in check_apps_ready Nov 24 15:13:06 ubuntu daphne[3125951]: raise AppRegistryNotReady(“Apps aren’t loaded yet.”) Nov 24 15:13:06 ubuntu daphne[3125951]: django.core.exceptions.AppRegistryNotReady: Apps aren’t loaded yet. `

I’m running :

python 3.8.5 daphne v3.0.1 gunicorn v20.0.4 nginx v1.18.0 redis v3.5.3 channels v3.0.2 channels-redis v3.2.0 django v3.1.3

asgi.py :

import os from channels.routing import ProtocolTypeRouter, URLRouter from django.core.asgi import get_asgi_application from chat.auth.jwt_auth_middleware import SimpleJwtTokenAuthMiddleware from chat import routing as core_routing

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'demo_API.settings') django_asgi_app = get_asgi_application()

application = ProtocolTypeRouter({ "http": django_asgi_app, "websocket": SimpleJwtTokenAuthMiddleware( URLRouter( core_routing.websocket_urlpatterns ) ), })

routing.py (in chat app) :

from . import consumers from django.urls import re_path

websocket_urlpatterns = [ re_path(r'^chatws$', consumers.ChatConsumer.as_asgi()), ]

settings.py :

INSTALLED_APPS = [ 'channels', 'chat', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'rest_framework_simplejwt', ] ASGI_APPLICATION = ‘demo_API.asgi.application’`

CHANNEL_LAYERS = { 'default': { 'BACKEND': 'channels_redis.core.RedisChannelLayer', 'CONFIG': { "hosts": ['127.0.0.1', 6379)], }, }, } `

wsgi.py :

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'demo_API.settings')

application = get_wsgi_application()

/etc/systemd/system/daphne.service :

[Unit] Description=daphne daemon After=network.target

[Service] PIDFile=/run/daphne/pid User=git Group=www-data WorkingDirectory=/home/git/demo_API/www/ Environment="DJANGO_SETTINGS_MODULE=demo_API.settings" ExecStart=/home/git/demo_API/www/venv/bin/daphne -u /home/git/demo_API/www/demo_chat.sock demo_API.asgi:application -v 1 --access-log /home/git/demo_API/www/logs/debug.log ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID Restart=on-abort PrivateTmp=true

[Install] WantedBy=multi-user.target

If i get everything back to old version it works again using old channels code & files. channels==2.4.0 daphne==2.5.0 channels-redis==2.4.1

Things i tried so far :

  • Removing all old daphne versions.

  • Installing daphne using a superuser session.

  • Changing the order of installed apps on settings.py.

  • Running daphne without -u .sock.

  • Tested AuthMiddleware instead of my custom SimpleJwtTokenAuthMiddleware in asgi.py + testing without Auths.

  • Running daphne command line directly on django folder.

And nothing seems to work so far.

Also same error on local running just : daphne demo_API.asgi:application

Details :

(venv) altroo@Altroo demo_API % daphne demo_API.asgi:application Traceback (most recent call last): File “/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/bin/daphne”, line 8, in <module> sys.exit(CommandLineInterface.entrypoint()) File “/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/lib/python3.8/site-packages/daphne/cli.py”, line 170, in entrypoint cls().run(sys.argv[1:]) File “/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/lib/python3.8/site-packages/daphne/cli.py”, line 232, in run application = import_by_path(args.application) File “/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/lib/python3.8/site-packages/daphne/utils.py”, line 12, in import_by_path target = importlib.import_module(module_path) File “/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/init.py”, line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File “<frozen importlib._bootstrap>”, line 1014, in _gcd_import File “<frozen importlib._bootstrap>”, line 991, in _find_and_load File “<frozen importlib._bootstrap>”, line 975, in _find_and_load_unlocked File “<frozen importlib._bootstrap>”, line 671, in _load_unlocked File “<frozen importlib._bootstrap_external>”, line 783, in exec_module File “<frozen importlib._bootstrap>”, line 219, in _call_with_frames_removed File “./demo_API/asgi.py”, line 15, in <module> from chat.auth.jwt_auth_middleware import SimpleJwtTokenAuthMiddleware File “./chat/auth/jwt_auth_middleware.py”, line 1, in <module> from channels.auth import AuthMiddlewareStack File “/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/lib/python3.8/site-packages/channels/auth.py”, line 12, in <module> from django.contrib.auth.models import AnonymousUser File “/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/lib/python3.8/site-packages/django/contrib/auth/models.py”, line 2, in <module> from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager File “/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/lib/python3.8/site-packages/django/contrib/auth/base_user.py”, line 48, in <module> class AbstractBaseUser(models.Model): File “/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/lib/python3.8/site-packages/django/db/models/base.py”, line 108, in __ new __ app_config = apps.get_containing_app_config(module) File “/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/lib/python3.8/site-packages/django/apps/registry.py”, line 253, in get_containing_app_config self.check_apps_ready() File “/Applications/XAMPP/xamppfiles/htdocs/demo_API/venv/lib/python3.8/site-packages/django/apps/registry.py”, line 136, in check_apps_ready raise AppRegistryNotReady(“Apps aren’t loaded yet.”) django.core.exceptions.AppRegistryNotReady: Apps aren’t loaded yet.

Any help or suggestions will be apreciated.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

32reactions
carltongibsoncommented, Nov 24, 2020

Hi @Altroo.

See the updated deployment docs here:

https://channels.readthedocs.io/en/stable/deploying.html#configuring-the-asgi-application

I think the issue will be the JWT auth middleware. Looks like it’s accessing the user model before this line:

django_asgi_app = get_asgi_application()

I’d say that if you move that import below there it should work.

2reactions
Altroocommented, Nov 25, 2020

Hi @Altroo.

See the updated deployment docs here:

https://channels.readthedocs.io/en/stable/deploying.html#configuring-the-asgi-application

I think the issue will be the JWT auth middleware. Looks like it’s accessing the user model before this line:

django_asgi_app = get_asgi_application()

I’d say that if you move that import below there it should work.

You’re a wizard harry ! thank’s alot it really worked, many daphne users really have this same issue on stackoverflow, your answer will save them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django apps aren't loaded yet when using asgi - Stack Overflow
Now, as you can see it's standard setup and it works fine with default django server but when I try to run with...
Read more >
Django apps aren't loaded yet when using asgi-django
I'm tring to run my django project with usage of asgi instead of wsgi. I have set up my routing.py and asgi.py as...
Read more >
ASGI errors when deploying Django project for production ...
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. This typically means you are trying to load models from some other module before django ...
Read more >
Apps Aren't Loaded Yet" When Deploying To Heroku - ADocLib
Django + Celery Apps aren't loaded yet. problem. Hello I'm trying to add some background tasks to my django project But It's seems...
Read more >
Deploying — Channels 4.0.0 documentation
Channels (ASGI) applications deploy similarly to WSGI applications - you load them into a server, like Daphne, and you can scale the number...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found