master问题修复

This commit is contained in:
朱潮 2026-03-17 12:17:46 +08:00
parent 36f2a5b87a
commit 09c4d5e804

View File

@ -346,6 +346,10 @@ async def get_parent_user_id(user_id: str) -> Optional[str]:
Returns:
Optional[str]: 主账号ID如果不是子账号则返回自身ID
"""
# masterkey 用户无需查询数据库
if user_id == "__masterkey__":
return user_id
pool = get_db_pool_manager().pool
async with pool.connection() as conn:
async with conn.cursor() as cursor:
@ -1703,6 +1707,7 @@ async def get_bot_settings(bot_uuid: str, authorization: Optional[str] = Header(
# 获取用户可用的模型列表
models_list = []
try:
if user_id != "__masterkey__":
async with pool.connection() as conn:
async with conn.cursor() as cursor:
# 获取用户的 new_api_session 和 new_api_user_id子账号使用主账号的
@ -1756,7 +1761,10 @@ async def get_bot_settings(bot_uuid: str, authorization: Optional[str] = Header(
bot_id, bot_name, settings_json, updated_at, is_published, copied_from, owner_id = row
settings = settings_json if settings_json else {}
# 判断当前用户是否是所有者子账号使用主账号ID判断
# 判断当前用户是否是所有者子账号使用主账号ID判断masterkey 视为所有者)
if user_id == "__masterkey__":
is_owner = True
else:
effective_user_id = await get_parent_user_id(user_id)
is_owner = (str(owner_id) == str(effective_user_id))
@ -1800,13 +1808,14 @@ async def get_bot_settings(bot_uuid: str, authorization: Optional[str] = Header(
# 处理 dataset_ids
# 单智能体模式:加载用户的所有知识库(子账号使用主账号的知识库)
# 普通模式:从 settings 读取
if SINGLE_AGENT_MODE:
if SINGLE_AGENT_MODE and user_id != "__masterkey__":
effective_user_id_for_ds = await get_parent_user_id(user_id) if user_id != "__masterkey__" else user_id
await cursor.execute("""
SELECT dataset_id
FROM user_datasets
WHERE user_id = %s
ORDER BY created_at DESC
""", (effective_user_id,))
""", (effective_user_id_for_ds,))
user_datasets = await cursor.fetchall()
dataset_ids = [row[0] for row in user_datasets] if user_datasets else []
else: