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:
Mavis
2026-06-07 23:22:56 +08:00
parent 2e75985a3c
commit 5109d6f824
8 changed files with 147 additions and 36 deletions

View File

@@ -16,13 +16,14 @@ def run(cmd, t=60):
return out
run("cd /srv/news && sudo -u news git pull --rebase 2>&1 | tail -3")
run("cd /srv/news && sg docker -c 'docker compose up -d --force-recreate caddy' 2>&1 | tail -10")
time.sleep(5)
# 重启 caddy + api
run("cd /srv/news && sg docker -c 'docker compose up -d --force-recreate caddy api' 2>&1 | tail -8")
time.sleep(8)
# 测试路径
print("\n=== healthz 测试 ===")
run("curl -s -o /dev/null -w 'healthz: %{http_code}\\n' http://localhost/healthz")
run("curl -s -o /dev/null -w 'api/healthz: %{http_code}\\n' http://localhost/api/healthz")
run("curl -s -o /dev/null -w 'api/v1/articles: %{http_code}\\n' http://localhost/api/v1/articles")
run("curl -s http://localhost/api/healthz 2>&1")
print("\n=== 验证 ===")
run("curl -s -o /dev/null -w 'healthz: %{http_code}\\n' http://localhost/api/v1/healthz")
run("curl -s http://localhost/api/v1/healthz 2>&1")
run("curl -s -o /dev/null -w 'articles (no auth): %{http_code}\\n' http://localhost/api/v1/articles")
run("curl -s http://localhost/api/v1/articles 2>&1")
run("curl -s -o /dev/null -w 'login OPTIONS: %{http_code}\\n' -X OPTIONS http://localhost/api/v1/auth/login")
c.close()