fix(api): fix the issue that prefilled conv var not commited

pull/20699/head
QuantumGhost 12 months ago
parent eeab59215a
commit 83d6a5e92a

@ -306,6 +306,7 @@ class ConversationVariableCollectionApi(Resource):
raise NotFoundError(description=f"draft workflow not found, id={app_model.id}") raise NotFoundError(description=f"draft workflow not found, id={app_model.id}")
draft_var_srv = WorkflowDraftVariableService(db.session()) draft_var_srv = WorkflowDraftVariableService(db.session())
draft_var_srv.prefill_conversation_variable_default_values(draft_workflow) draft_var_srv.prefill_conversation_variable_default_values(draft_workflow)
db.session.commit()
return _get_variable_list(app_model, CONVERSATION_VARIABLE_NODE_ID) return _get_variable_list(app_model, CONVERSATION_VARIABLE_NODE_ID)

@ -324,19 +324,10 @@ class WorkflowService:
if not draft_workflow: if not draft_workflow:
raise ValueError("Workflow not initialized") raise ValueError("Workflow not initialized")
# TODO(QuantumGhost): We may get rid of the `list_conversation_variables` with Session(bind=db.engine, expire_on_commit=False) as session, session.begin():
# here, and rely on `DraftVarLoader` to load conversation variables.
with Session(bind=db.engine) as session:
draft_var_srv = WorkflowDraftVariableService(session) draft_var_srv = WorkflowDraftVariableService(session)
draft_var_srv.prefill_conversation_variable_default_values(draft_workflow) 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_config = draft_workflow.get_node_config_by_id(node_id)
node_type = NodeType(node_config.get("data", {}).get("type")) node_type = NodeType(node_config.get("data", {}).get("type"))
if node_type == NodeType.START: if node_type == NodeType.START:
@ -355,7 +346,8 @@ class WorkflowService:
user_id=account.id, user_id=account.id,
user_inputs=user_inputs, user_inputs=user_inputs,
workflow=draft_workflow, workflow=draft_workflow,
conversation_variables=conv_vars, # NOTE(QuantumGhost): We rely on `DraftVarLoader` to load conversation variables.
conversation_variables=[],
node_type=node_type, node_type=node_type,
conversation_id=conversation_id, conversation_id=conversation_id,
) )

Loading…
Cancel
Save