From 83d6a5e92ad67ff66860d30fb5f37bf97043ca86 Mon Sep 17 00:00:00 2001 From: QuantumGhost Date: Wed, 4 Jun 2025 20:12:40 +0800 Subject: [PATCH] fix(api): fix the issue that prefilled conv var not commited --- .../console/app/workflow_draft_variable.py | 1 + api/services/workflow_service.py | 14 +++----------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/api/controllers/console/app/workflow_draft_variable.py b/api/controllers/console/app/workflow_draft_variable.py index 73b0b830ab..c2652fcc04 100644 --- a/api/controllers/console/app/workflow_draft_variable.py +++ b/api/controllers/console/app/workflow_draft_variable.py @@ -306,6 +306,7 @@ class ConversationVariableCollectionApi(Resource): raise NotFoundError(description=f"draft workflow not found, id={app_model.id}") draft_var_srv = WorkflowDraftVariableService(db.session()) draft_var_srv.prefill_conversation_variable_default_values(draft_workflow) + db.session.commit() return _get_variable_list(app_model, CONVERSATION_VARIABLE_NODE_ID) diff --git a/api/services/workflow_service.py b/api/services/workflow_service.py index 063b08ab9a..6f2f943603 100644 --- a/api/services/workflow_service.py +++ b/api/services/workflow_service.py @@ -324,19 +324,10 @@ class WorkflowService: if not draft_workflow: raise ValueError("Workflow not initialized") - # TODO(QuantumGhost): We may get rid of the `list_conversation_variables` - # here, and rely on `DraftVarLoader` to load conversation variables. - - with Session(bind=db.engine) as session: + with Session(bind=db.engine, expire_on_commit=False) as session, session.begin(): draft_var_srv = WorkflowDraftVariableService(session) draft_var_srv.prefill_conversation_variable_default_values(draft_workflow) - conv_vars_models = draft_var_srv.list_conversation_variables(app_id=app_model.id) - conv_vars = [ - segment_to_variable(segment=v.get_value(), id=v.id, selector=v.get_selector()) - for v in conv_vars_models.variables - ] - node_config = draft_workflow.get_node_config_by_id(node_id) node_type = NodeType(node_config.get("data", {}).get("type")) if node_type == NodeType.START: @@ -355,7 +346,8 @@ class WorkflowService: user_id=account.id, user_inputs=user_inputs, workflow=draft_workflow, - conversation_variables=conv_vars, + # NOTE(QuantumGhost): We rely on `DraftVarLoader` to load conversation variables. + conversation_variables=[], node_type=node_type, conversation_id=conversation_id, )