fix: AsyncEngine不支持直接inspect,改用session.run_sync获取表列信息
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user