From 6bae477fc0518c8b7ca3910a1d23e5f02458b425 Mon Sep 17 00:00:00 2001 From: QuantumGhost Date: Mon, 16 Jun 2025 10:24:25 +0800 Subject: [PATCH] fix(api): retain the type of draft variable while updating its value --- .../console/app/workflow_draft_variable.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/api/controllers/console/app/workflow_draft_variable.py b/api/controllers/console/app/workflow_draft_variable.py index ff9ae65439..d0e7c20c2e 100644 --- a/api/controllers/console/app/workflow_draft_variable.py +++ b/api/controllers/console/app/workflow_draft_variable.py @@ -16,7 +16,7 @@ from controllers.web.error import InvalidArgumentError, NotFoundError from core.variables.segment_group import SegmentGroup from core.variables.segments import ArrayFileSegment, FileSegment, Segment from core.workflow.constants import CONVERSATION_VARIABLE_NODE_ID, SYSTEM_VARIABLE_NODE_ID -from factories.variable_factory import build_segment +from factories.variable_factory import build_segment_with_type from libs.login import current_user, login_required from models import App, AppMode, db from models.workflow import WorkflowDraftVariable @@ -236,7 +236,8 @@ class VariableApi(Resource): def patch(self, app_model: App, variable_id: str): parser = reqparse.RequestParser() parser.add_argument(self._PATCH_NAME_FIELD, type=str, required=False, nullable=True, location="json") - parser.add_argument(self._PATCH_VALUE_FIELD, type=build_segment, required=False, nullable=True, location="json") + # Parse 'value' field as-is to maintain its original data structure + parser.add_argument(self._PATCH_VALUE_FIELD, type=lambda x: x, required=False, nullable=True, location="json") draft_var_srv = WorkflowDraftVariableService( session=db.session(), @@ -250,10 +251,13 @@ class VariableApi(Resource): raise NotFoundError(description=f"variable not found, id={variable_id}") new_name = args.get(self._PATCH_NAME_FIELD, None) - new_value = args.get(self._PATCH_VALUE_FIELD, None) - - if new_name is None and new_value is None: + raw_value = args.get(self._PATCH_VALUE_FIELD, None) + if new_name is None and raw_value is None: return variable + + new_value = None + if raw_value is not None: + new_value = build_segment_with_type(variable.value_type, raw_value) draft_var_srv.update_variable(variable, name=new_name, value=new_value) db.session.commit() return variable