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}