From 3bd86b94edde2f0d0edf62982b31dec58742faa9 Mon Sep 17 00:00:00 2001 From: Pine Date: Sun, 6 Sep 2026 20:55:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20AsyncEngine=E4=B8=8D=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5inspect,=E6=94=B9=E7=94=A8session.run=5Fsync?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=A1=A8=E5=88=97=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/routers/rbac_admin.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/app/api/routers/rbac_admin.py b/app/api/routers/rbac_admin.py index 9295da4..5454264 100644 --- a/app/api/routers/rbac_admin.py +++ b/app/api/routers/rbac_admin.py @@ -242,15 +242,20 @@ async def delete_user( # 获取数据库中所有表的列信息,避免对没有 user_id 的表执行删除 from sqlalchemy import inspect as sa_inspect - insp = sa_inspect(db.session.bind) - tables_with_user_id = set() - for tname in cascade_tables: - try: - cols = [c["name"] for c in insp.get_columns(tname)] - if "user_id" in cols: - tables_with_user_id.add(tname) - except Exception: - pass + + def _get_tables_with_user_id(sync_conn): + insp = sa_inspect(sync_conn) + result = set() + for tname in cascade_tables: + try: + cols = [c["name"] for c in insp.get_columns(tname)] + if "user_id" in cols: + result.add(tname) + except Exception: + pass + return result + + tables_with_user_id = await db.session.run_sync(_get_tables_with_user_id) deleted_count = 0 for table in tables_with_user_id: