Closed zspine closed 2 months ago
The issue can be temporarily resolved by using the following workaround:
# backend/apps/webui/routers/users.py
@router.post("/user/settings/update", response_model=UserSettings)
async def update_user_settings_by_session_user(
form_data: UserSettings, user=Depends(get_verified_user)
):
# Get the current user settings
current_user = Users.get_user_by_id(user.id)
if not current_user:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=ERROR_MESSAGES.USER_NOT_FOUND,
)
# Get the current settings or initialize if None
current_settings = current_user.settings.model_dump() if current_user.settings else {"ui": {},
"functions": {"valves": {}}}
# Update the settings
new_settings = form_data.model_dump()
# Update 'ui' if present in new settings
if "ui" in new_settings:
current_settings["ui"].update(new_settings["ui"])
# Update 'functions.valves' if present in new settings
if "functions" in new_settings and "valves" in new_settings["functions"]:
if "functions" not in current_settings:
current_settings["functions"] = {"valves": {}}
current_settings["functions"]["valves"].update(new_settings["functions"]["valves"])
# Update the user in the database
updated_user = Users.update_user_by_id(user.id, {"settings": current_settings})
if updated_user:
return updated_user.settings
else:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=ERROR_MESSAGES.USER_NOT_FOUND,
)
Bug Report
When using the 'Set as default' button from the main chat screen, it overrides all previously saved UserValves function settings.
Installation Method
Docker
Environment
Expected Behavior:
When any action triggers the '/user/settings/update' API endpoint, it should preserve all previously stored user settings.
Actual Behavior:
Any action triggering the '/user/settings/update' API endpoint stores only the values related to 'ui' and wipes all previously saved key values for other settings.
Specifically, when the 'Set as default' button is clicked, it clears all previously saved UserValves function settings, including custom function configurations and API key values.
Reproduction Details
Steps to Reproduce:
/workspace/functions/
workspace.Following these steps should reproduce the issue. The 'Set as default' button should preserve all previously saved user settings, including custom function configurations and API key values. Instead, it currently overrides these settings, leading to data loss.