fix: 修剩余的 (await ...)).scalar_one_or_none() 链式 + bookmark

This commit is contained in:
Mavis
2026-06-07 23:25:53 +08:00
parent 5109d6f824
commit ce903ac58e
3 changed files with 38 additions and 38 deletions

View File

@@ -21,7 +21,8 @@ async def add(
user: User = Depends(get_current_user),
session: AsyncSession = Depends(get_session),
):
art = (await session.execute(select(Article).where(Article.id == body.article_id))).scalar_one_or_none()
result = await session.execute(select(Article).where(Article.id == body.article_id))
art = result.scalar_one_or_none()
if not art:
raise HTTPException(status.HTTP_404_NOT_FOUND, "Article not found")
# 已存在则直接返回