mirror of https://github.com/langgenius/dify.git
fix(api): make app list robust when workflow graph nodes missing
This commit is contained in:
parent
b353a126d8
commit
5c1a543fa3
|
|
@ -242,8 +242,11 @@ class AppListApi(Resource):
|
|||
NodeType.TRIGGER_PLUGIN,
|
||||
}
|
||||
for workflow in draft_workflows:
|
||||
for _, node_data in workflow.walk_nodes():
|
||||
if node_data.get("type") in trigger_node_types:
|
||||
graph = workflow.graph_dict
|
||||
nodes = graph.get("nodes", [])
|
||||
for node in nodes:
|
||||
node_type = node.get("data", {}).get("type")
|
||||
if node_type in trigger_node_types:
|
||||
draft_trigger_app_ids.add(str(workflow.app_id))
|
||||
break
|
||||
|
||||
|
|
|
|||
|
|
@ -235,13 +235,7 @@ class Workflow(Base): # bug
|
|||
the node's id, title, and its data as a dict.
|
||||
"""
|
||||
workflow_graph = self.graph_dict
|
||||
|
||||
if not workflow_graph:
|
||||
raise WorkflowDataError(f"workflow graph not found, workflow_id={self.id}")
|
||||
|
||||
nodes = workflow_graph.get("nodes")
|
||||
if not nodes:
|
||||
raise WorkflowDataError("nodes not found in workflow graph")
|
||||
nodes = workflow_graph.get("nodes", [])
|
||||
|
||||
try:
|
||||
node_config: dict[str, Any] = next(filter(lambda node: node["id"] == node_id, nodes))
|
||||
|
|
@ -347,17 +341,16 @@ class Workflow(Base): # bug
|
|||
For specific node type, refer to `core.workflow.nodes`
|
||||
"""
|
||||
graph_dict = self.graph_dict
|
||||
if "nodes" not in graph_dict:
|
||||
raise WorkflowDataError("nodes not found in workflow graph")
|
||||
nodes = graph_dict.get("nodes", [])
|
||||
|
||||
if specific_node_type:
|
||||
yield from (
|
||||
(node["id"], node["data"])
|
||||
for node in graph_dict["nodes"]
|
||||
if node["data"]["type"] == specific_node_type.value
|
||||
(node["id"], node.get("data", {}))
|
||||
for node in nodes
|
||||
if node.get("data", {}).get("type") == specific_node_type.value
|
||||
)
|
||||
else:
|
||||
yield from ((node["id"], node["data"]) for node in graph_dict["nodes"])
|
||||
yield from ((node["id"], node.get("data", {})) for node in nodes)
|
||||
|
||||
def user_input_form(self, to_old_structure: bool = False) -> list[Any]:
|
||||
# get start node from graph
|
||||
|
|
@ -365,13 +358,9 @@ class Workflow(Base): # bug
|
|||
return []
|
||||
|
||||
graph_dict = self.graph_dict
|
||||
if "nodes" not in graph_dict:
|
||||
return []
|
||||
nodes = graph_dict.get("nodes", [])
|
||||
|
||||
start_node = next(
|
||||
(node for node in graph_dict["nodes"] if node["data"]["type"] == "start"),
|
||||
None,
|
||||
)
|
||||
start_node = next((node for node in nodes if node.get("data", {}).get("type") == "start"), None)
|
||||
if not start_node:
|
||||
return []
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue