python runtime_error ai_generated true

RuntimeWarning: 协程 'get_data' 从未被 await

RuntimeWarning: coroutine 'get_data' was never awaited

ID: python/fastapi-await-missing

其他格式: JSON · Markdown 中文 · English
80%修复率
89%置信度
0证据数
2024-07-29首次发现

版本兼容性

版本状态引入弃用备注
3.x active — — —

根因分析

在异步路由中调用异步函数时未使用 await,导致返回协程对象而非数据。

English

An async function was called without await inside an async route, so the coroutine object was returned instead of data.

generic

解决方案

  1. 95% 成功率
    data = await get_data()
  2. 85% 成功率
    Make route sync def and call sync version of helper

无效尝试

常见但无效的做法:

  1. 85% 失败

    Cannot run event loop inside a running loop; raises RuntimeError.

  2. 80% 失败

    Silences signal but response body is still a coroutine.