sentry-python: SentryAsgiMiddleware not compatible with Uvicorn 0.13.0
On December 8th Uvicorn updated from 0.12.3 to 0.13.0. This results in an error at startup, see output with minimal example. When downgrading Uvicorn to 0.12.3 the example runs fine.
Why this error is thrown or which changes resulted in the error, I have no clue. Could you help me with this?
app.py
from sanic import Sanic
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
app = SentryAsgiMiddleware(Sanic(__name__))
requirements.txt
sanic==20.9.1
sentry-sdk==0.19.4
uvicorn==0.13.0
Command to run:
uvicorn app:app --port 5000 --workers=1 --debug --reload
Output:
INFO: Uvicorn running on http://127.0.0.1:5000 (Press CTRL+C to quit)
INFO: Started reloader process [614068] using statreload
Process SpawnProcess-1:
Traceback (most recent call last):
File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/usr/lib/python3.9/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/home/lander/.local/share/virtualenvs/san-iJ5wdX60/lib/python3.9/site-packages/uvicorn/subprocess.py", line 61, in subprocess_started
target(sockets=sockets)
File "/home/lander/.local/share/virtualenvs/san-iJ5wdX60/lib/python3.9/site-packages/uvicorn/server.py", line 48, in run
loop.run_until_complete(self.serve(sockets=sockets))
File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete
File "/home/lander/.local/share/virtualenvs/san-iJ5wdX60/lib/python3.9/site-packages/uvicorn/server.py", line 55, in serve
config.load()
File "/home/lander/.local/share/virtualenvs/san-iJ5wdX60/lib/python3.9/site-packages/uvicorn/config.py", line 319, in load
elif not inspect.signature(self.loaded_app).parameters:
File "/usr/lib/python3.9/inspect.py", line 3118, in signature
return Signature.from_callable(obj, follow_wrapped=follow_wrapped)
File "/usr/lib/python3.9/inspect.py", line 2867, in from_callable
return _signature_from_callable(obj, sigcls=cls,
File "/usr/lib/python3.9/inspect.py", line 2409, in _signature_from_callable
sig = _signature_from_callable(
File "/usr/lib/python3.9/inspect.py", line 2242, in _signature_from_callable
raise TypeError('{!r} is not a callable object'.format(obj))
TypeError: <member '__call__' of 'SentryAsgiMiddleware' objects> is not a callable object
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 6
- Comments: 33 (9 by maintainers)
I think this issue can be closed, after the implemented fixes.
It doesn’t, but due to the
__call__trick the code that Uvicorn was using to decide whether an app was a factory or not was failing. 😃Hey folks,
Could anyone using the Sentry ASGI middleware install Uvicorn from https://github.com/encode/uvicorn/pull/914 as a quick confirmation that it fixes the problem seen here?
Arggh, my bad. Missed comment https://github.com/getsentry/sentry-python/issues/947#issuecomment-747993502 which already does this! Wasted quite some time on this investigation!
@florimondmanca works for me!