diff --git a/backend/app/services/settings_service.py b/backend/app/services/settings_service.py index e3f428b..ab31f37 100644 --- a/backend/app/services/settings_service.py +++ b/backend/app/services/settings_service.py @@ -49,12 +49,17 @@ async def update_user_profile( async def update_llm_config(user_id: str, config: dict, db: AsyncSession) -> dict: """更新 LLM 配置""" + import copy + logger.info(f"update_llm_config called with config keys: {list(config.keys())}") + logger.info(f"chat config: {config.get('chat')}") result = await db.execute(select(User).where(User.id == user_id)) user = result.scalar_one_or_none() if not user: raise ValueError("用户不存在") - current = user.llm_config or {} + # 创建深拷贝,避免 SQLAlchemy 变更检测问题 + current = copy.deepcopy(user.llm_config) or {} + logger.info(f"current llm_config before update: {current}") # 合并配置 - 直接替换整个类型配置列表 for key, value in config.items(): if value is not None: @@ -69,8 +74,11 @@ async def update_llm_config(user_id: str, config: dict, db: AsyncSession) -> dic current[key] = value else: current[key] = value + logger.info(f"current llm_config after update: {current}") user.llm_config = current await db.commit() + await db.refresh(user) + logger.info(f"user.llm_config after refresh: {user.llm_config}") return current