fix: API 全部改用显式两步走 await session.execute + result.scalars()
之前 (await ...).scalars() 链式在 SQLAlchemy 2.0 async 下报 'coroutine' has no attribute 'scalars' 错误。改为先 await 拿 result 再 .scalars(),这是 SQLAlchemy 2.0 推荐的 async 写法。
This commit is contained in:
@@ -19,7 +19,6 @@ async def list_sources(
|
||||
user: User = Depends(get_current_user), # noqa: ARG001
|
||||
session: AsyncSession = Depends(get_session),
|
||||
):
|
||||
rows = (
|
||||
await session.execute(select(Source).order_by(Source.priority.desc(), Source.name))
|
||||
).scalars()
|
||||
result = await session.execute(select(Source).order_by(Source.priority.desc(), Source.name))
|
||||
rows = result.scalars()
|
||||
return [SourceOut.model_validate(s) for s in rows]
|
||||
|
||||
Reference in New Issue
Block a user