Skip to content

Commit 3f885b3

Browse files
committed
Fix route discovery on starlette < 0.20.1
starlette._utils.is_async_callable was introduced in 0.20.1. On older versions (e.g. 0.16.0 used by FastAPI 0.70.0) the ImportError caused an early return, skipping the post_response handler entirely. This meant routes were never recorded in heartbeats. Fall back to inspect.iscoroutinefunction when _utils is unavailable.
1 parent 007719c commit 3f885b3

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

aikido_zen/sources/starlette/starlette_routing.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,16 @@ async def aikido_route_func(*args, **kwargs):
4545
try:
4646
import functools
4747
from starlette.concurrency import run_in_threadpool
48-
from starlette._utils import is_async_callable
4948
except ImportError:
50-
logger.info("Make sure starlette install OK : .concurrency, ._utils")
49+
logger.info("Make sure starlette install OK : .concurrency")
5150
return await func(*args, **kwargs)
51+
try:
52+
from starlette._utils import is_async_callable
53+
except ImportError:
54+
# starlette < 0.20.1 doesn't have _utils.is_async_callable
55+
import inspect
56+
57+
is_async_callable = inspect.iscoroutinefunction
5258
res = None
5359
if is_async_callable(func):
5460
res = await func(*args, **kwargs)

0 commit comments

Comments
 (0)