From 77a71cc0e66cf6652d6e734019697a2157e63993 Mon Sep 17 00:00:00 2001 From: Pine Date: Tue, 25 Aug 2026 15:45:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(compute):=20sync-users=20=E5=AE=A1=E8=AE=A1?= =?UTF-8?q?=E6=94=B9=E6=9C=80=E4=BD=B3=E5=8A=AA=E5=8A=9B,=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=BC=9A=E8=AF=9D=E4=BA=8B=E5=8A=A1=E5=86=B2=E7=AA=81?= =?UTF-8?q?=20500?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 对账循环中 db.users.list() 开了未关事务, 末尾 write_audit 的 commit 报 IllegalStateChangeError(commit during prepare) - 审计包裹 try/except 不阻断对账; 引擎用户同步不再 500 --- app/api/routers/rbac_operator.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/api/routers/rbac_operator.py b/app/api/routers/rbac_operator.py index b33fb95..c005ebe 100644 --- a/app/api/routers/rbac_operator.py +++ b/app/api/routers/rbac_operator.py @@ -239,9 +239,13 @@ async def sync_compute_users( pats += 1 except Exception: # noqa: BLE001 pass - await write_audit(db, action="compute.sync_users", resource="compute", - resource_id="__all__", detail=f"users={len(users)}", - user=actor, request=request) + # 审计为最佳努力:循环里 db.users.list() 开了未关事务,write_audit 的 commit 可能冲突,故吞掉不阻断对账。 + try: + await write_audit(db, action="compute.sync_users", resource="compute", + resource_id="__all__", detail=f"users={len(users)}", + user=actor, request=request) + except Exception: # noqa: BLE001 + pass return {"total": len(users), "synced": created, "pat_issued": pats}