fix: articles.py get_article 链式 await coroutine 报错(.first())

This commit is contained in:
Mavis
2026-06-08 00:19:03 +08:00
parent cc02d39d29
commit e79cfaa5f7
13 changed files with 598 additions and 8 deletions

View File

@@ -95,7 +95,8 @@ async def list_articles(
stmt = stmt.order_by(desc(Article.published_at), desc(Article.id)).limit(limit + 1)
rows = (await session.execute(stmt)).all()
result = await session.execute(stmt)
rows = result.all()
has_more = len(rows) > limit
rows = rows[:limit]
@@ -140,14 +141,12 @@ async def get_article(
user: User = Depends(get_current_user),
session: AsyncSession = Depends(get_session),
):
art = (
await session.execute(
select(Article, Source)
.join(Source, Source.id == Article.source_id)
.where(Article.id == article_id)
)
.first()
result = await session.execute(
select(Article, Source)
.join(Source, Source.id == Article.source_id)
.where(Article.id == article_id)
)
art = result.first()
if not art:
raise HTTPException(status.HTTP_404_NOT_FOUND, "Article not found")
article, source = art