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:
@@ -38,13 +38,12 @@ async def list_mine(
|
||||
user: User = Depends(get_current_user),
|
||||
session: AsyncSession = Depends(get_session),
|
||||
):
|
||||
rows = (
|
||||
await session.execute(
|
||||
select(Subscription)
|
||||
.where(Subscription.user_id == user.id)
|
||||
.order_by(Subscription.created_at.desc())
|
||||
)
|
||||
).scalars()
|
||||
result = await session.execute(
|
||||
select(Subscription)
|
||||
.where(Subscription.user_id == user.id)
|
||||
.order_by(Subscription.created_at.desc())
|
||||
)
|
||||
rows = result.scalars()
|
||||
return [SubscriptionOut.model_validate(s) for s in rows]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user