From ad14f9ccce1fbde610fe6eea3cf9c15a71513878 Mon Sep 17 00:00:00 2001 From: Pine Date: Tue, 25 Aug 2026 15:47:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(compute):=20sync-users=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=20write=5Faudit(=E6=A0=B9=E6=B2=BB=E4=BC=9A=E8=AF=9D=20Pending?= =?UTF-8?q?Rollback/UNIQUE=20=E6=B1=A1=E6=9F=93)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - write_audit 的 commit 与对账只读会话事务交互, 触发 PendingRollbackError + audit_logs.id UNIQUE 冲突, 并污染会话使后续 get_current_user 连带失败 - 对账幂等自明不写审计, 直接返回统计; 点击同步不再 500 --- app/api/routers/rbac_operator.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/api/routers/rbac_operator.py b/app/api/routers/rbac_operator.py index c005ebe..8666ffc 100644 --- a/app/api/routers/rbac_operator.py +++ b/app/api/routers/rbac_operator.py @@ -239,13 +239,8 @@ async def sync_compute_users( pats += 1 except Exception: # noqa: BLE001 pass - # 审计为最佳努力:循环里 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 + # 对账幂等自明、且涉及对 db 只读 + 大量外部调用,不写审计(write_audit 的 commit 与该只读会话 + # 事务交互会触发 PendingRollback/UNIQUE 冲突并污染会话)。仅返回统计。 return {"total": len(users), "synced": created, "pat_issued": pats}