emmett-framework / granian

A Rust HTTP server for Python applications
BSD 3-Clause "New" or "Revised" License
2.86k stars 83 forks source link

ValueError: Django can only handle ASGI/HTTP connections, not lifespan. #153

Closed Zerotask closed 11 months ago

Zerotask commented 11 months ago

I'm using Django with ASGI granian 0.7.3:

granian --threads 8 --host 0.0.0.0 --port 8000 --interface asgi base.asgi:application

and I noticed the following in my Debian based docker container:

[WARNING] Exception in lifespan protocol Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/granian/asgi.py", line 24, in handle await self.callable( File "/usr/local/lib/python3.12/site-packages/sentry_sdk/integrations/django/asgi.py", line 80, in sentry_patched_asgi_handler return await middleware(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/sentry_sdk/integrations/asgi.py", line 146, in _run_asgi3 return await self._run_app(scope, receive, send, asgi_version=3) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/sentry_sdk/integrations/asgi.py", line 161, in _run_app raise exc from None File "/usr/local/lib/python3.12/site-packages/sentry_sdk/integrations/asgi.py", line 157, in _run_app return await self.app(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/core/handlers/asgi.py", line 155, in call raise ValueError( ValueError: Django can only handle ASGI/HTTP connections, not lifespan. [INFO] Started worker-1

I don't know if this issue is related to granian or the Sentry SDK.

gi0baro commented 11 months ago

That's just a warning, your app should be served correctly. Granian expects ASGI/3 interfaces, and lifespan is a part of the protocol. If the application doesn't support lifespan then Granian will just trigger that warning and keep going on.

We might consider to add an option to disable lifespan, but I'm gonna close this as it doesn't really cause any malfunctioning.

Zerotask commented 8 months ago

It would be great to have an option to disable lifespan. We're using Sentry and this warning is the reason our quota depletes after a few days making Sentry useless for us at the moment.

gi0baro commented 8 months ago

@Zerotask with 1.2.0 you can use --interface asginl

Zerotask commented 8 months ago

Thank you :) Already updated