diff --git a/tin/asgi.py b/tin/asgi.py index 9cfda6dd..cb4ac322 100644 --- a/tin/asgi.py +++ b/tin/asgi.py @@ -17,9 +17,13 @@ from django.core.asgi import get_asgi_application from django.urls import path -from .apps.submissions.consumers import SubmissionJsonConsumer - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tin.settings") +# Initialize Django ASGI application early to ensure the AppRegistry +# is populated before importing code that may import ORM models. +django_asgi_app = get_asgi_application() + + +from .apps.submissions.consumers import SubmissionJsonConsumer # fmt: off class WebsocketCloseConsumer(WebsocketConsumer): @@ -36,7 +40,7 @@ def disconnect(self, code): application = ProtocolTypeRouter( { - "http": get_asgi_application(), + "http": django_asgi_app, "websocket": AuthMiddlewareStack( URLRouter( [