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

@@ -67,7 +67,8 @@ async def update_source(
body: SourceUpdate,
session: AsyncSession = Depends(get_session),
):
result = await session.execute(select(Source).where(Source.id == source_id))).scalar_one_or_none()
result = await session.execute(select(Source).where(Source.id == source_id))
src = result.scalar_one_or_none()
if not src:
raise HTTPException(status.HTTP_404_NOT_FOUND, "Source not found")
for k, v in body.model_dump(exclude_unset=True).items():
@@ -79,7 +80,8 @@ async def update_source(
@router.delete("/sources/{source_id}", status_code=status.HTTP_204_NO_CONTENT)
async def delete_source(source_id: int, session: AsyncSession = Depends(get_session)):
src = (await session.execute(select(Source).where(Source.id == source_id))).scalar_one_or_none()
result = await session.execute(select(Source).where(Source.id == source_id))
src = result.scalar_one_or_none()
if not src:
raise HTTPException(status.HTTP_404_NOT_FOUND, "Source not found")
await session.delete(src)
@@ -99,7 +101,8 @@ async def refresh_source(
background: BackgroundTasks,
session: AsyncSession = Depends(get_session),
):
src = (await session.execute(select(Source).where(Source.id == source_id))).scalar_one_or_none()
result = await session.execute(select(Source).where(Source.id == source_id))
src = result.scalar_one_or_none()
if not src:
raise HTTPException(status.HTTP_404_NOT_FOUND, "Source not found")
if not src.enabled:
@@ -125,7 +128,8 @@ async def rerun_translation(
background: BackgroundTasks,
session: AsyncSession = Depends(get_session),
):
art = (await session.execute(select(Article).where(Article.id == article_id))).scalar_one_or_none()
result = await session.execute(select(Article).where(Article.id == article_id))
art = result.scalar_one_or_none()
if not art:
raise HTTPException(status.HTTP_404_NOT_FOUND, "Article not found")
art.translation_status = "pending"

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")
# 已存在则直接返回