0

The project is running on the local server, but when I try to run on the production server, it gives an error ImportError: cannot import name 'LastModMixin' from partially initialized module 'snippets.models.abstracts' (most likely due to a circular import), for example, if you delete this import, the error will be sent to another, and so on, I tried manual

import django
django.setup()

in settings.py, asgi.py, but doesn't work

this is my asgi.py

import os

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application
from channels.http import AsgiHandler

from apps.drivers import routing

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


application = ProtocolTypeRouter({
    "http": AsgiHandler(),
    "websocket": AuthMiddlewareStack(
        URLRouter(
            routing.websocket_urlpatterns
        )
    ),
})

the command with which I will start the server

gunicorn project.asgi --preload -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8009

also tried daphne -p 8009 project.asgi:application but the result is the same.

Thanks in advance

1 Answers1

1

It turned out that you need to call get_asgi_application() before calling the from my.app import routing, for this you need to do so django_asgi_app = get_asgi_application() from apps.drivers import routing so that django.setup() loads all modules before importing my.apps which is called inside get_asgi_application()

working asgi.py in my case

import os
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application

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

django_asgi_app = get_asgi_application() #colling first
from apps.drivers import routing # colling second

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