python
type_error
ai_generated
true
TypeError: object NoneType can't be used in 'await' expression
ID: python/fastapi-await-none-coroutine
80%Fix Rate
85%Confidence
0Evidence
2024-12-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
An async route awaits a call that is actually synchronous (e.g. a sync DB driver or a function returning None).
generic中文
异步路由 await 了一个实际上是同步的调用(例如同步数据库驱动或返回 None 的函数)。
Workarounds
-
88% success
Use an async driver or run sync in a threadpool: from starlette.concurrency import run_in_threadpool result = await run_in_threadpool(sync_fn)
-
90% success
Remove await when calling a synchronous function.
Dead Ends
Common approaches that don't work:
-
60% fail
Fixes this call but blocks the event loop for other requests.
-
85% fail
Doesn't make the awaited object awaitable.