找出异步订单读取器里的 bug

来自 FastAPI
FastAPI 0.141.1 / Python 3.14 进阶 4分钟 找出 2处问题

这个端点应只获取当前用户可见的订单,而且不能阻塞事件循环。找出两个边界错误。

Python
from fastapi import FastAPI

app = FastAPI()

@app.get("/orders/{order_id}")
async def read_order(order_id: int):
    order = sync_session.get(Order, order_id)
    return {"id": order.id, "total_cents": order.total_cents}
在试验场中打开
报告错误