fix: Variable Assigner node silently fails for legacy V1 data format (#28867)

This commit is contained in:
kinglisky 2025-12-05 15:27:18 +08:00 committed by GitHub
parent c2cf0a98bb
commit 02fdc5e2a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 8 deletions

View File

@ -64,7 +64,10 @@ class DifyNodeFactory(NodeFactory):
if not node_mapping:
raise ValueError(f"No class mapping found for node type: {node_type}")
node_class = node_mapping.get(LATEST_VERSION)
latest_node_class = node_mapping.get(LATEST_VERSION)
node_version = str(node_data.get("version", "1"))
matched_node_class = node_mapping.get(node_version)
node_class = matched_node_class or latest_node_class
if not node_class:
raise ValueError(f"No latest version class found for node type: {node_type}")

View File

@ -30,7 +30,13 @@ def test_overwrite_string_variable():
"nodes": [
{"data": {"type": "start", "title": "Start"}, "id": "start"},
{
"data": {"type": "assigner", "version": "1", "title": "Variable Assigner", "items": []},
"data": {
"type": "assigner",
"title": "Variable Assigner",
"assigned_variable_selector": ["conversation", "test_conversation_variable"],
"write_mode": "over-write",
"input_variable_selector": ["node_id", "test_string_variable"],
},
"id": "assigner",
},
],
@ -131,7 +137,13 @@ def test_append_variable_to_array():
"nodes": [
{"data": {"type": "start", "title": "Start"}, "id": "start"},
{
"data": {"type": "assigner", "version": "1", "title": "Variable Assigner", "items": []},
"data": {
"type": "assigner",
"title": "Variable Assigner",
"assigned_variable_selector": ["conversation", "test_conversation_variable"],
"write_mode": "append",
"input_variable_selector": ["node_id", "test_string_variable"],
},
"id": "assigner",
},
],
@ -231,7 +243,13 @@ def test_clear_array():
"nodes": [
{"data": {"type": "start", "title": "Start"}, "id": "start"},
{
"data": {"type": "assigner", "version": "1", "title": "Variable Assigner", "items": []},
"data": {
"type": "assigner",
"title": "Variable Assigner",
"assigned_variable_selector": ["conversation", "test_conversation_variable"],
"write_mode": "clear",
"input_variable_selector": [],
},
"id": "assigner",
},
],

View File

@ -78,7 +78,7 @@ def test_remove_first_from_array():
"nodes": [
{"data": {"type": "start", "title": "Start"}, "id": "start"},
{
"data": {"type": "assigner", "title": "Variable Assigner", "items": []},
"data": {"type": "assigner", "version": "2", "title": "Variable Assigner", "items": []},
"id": "assigner",
},
],
@ -162,7 +162,7 @@ def test_remove_last_from_array():
"nodes": [
{"data": {"type": "start", "title": "Start"}, "id": "start"},
{
"data": {"type": "assigner", "title": "Variable Assigner", "items": []},
"data": {"type": "assigner", "version": "2", "title": "Variable Assigner", "items": []},
"id": "assigner",
},
],
@ -243,7 +243,7 @@ def test_remove_first_from_empty_array():
"nodes": [
{"data": {"type": "start", "title": "Start"}, "id": "start"},
{
"data": {"type": "assigner", "title": "Variable Assigner", "items": []},
"data": {"type": "assigner", "version": "2", "title": "Variable Assigner", "items": []},
"id": "assigner",
},
],
@ -324,7 +324,7 @@ def test_remove_last_from_empty_array():
"nodes": [
{"data": {"type": "start", "title": "Start"}, "id": "start"},
{
"data": {"type": "assigner", "title": "Variable Assigner", "items": []},
"data": {"type": "assigner", "version": "2", "title": "Variable Assigner", "items": []},
"id": "assigner",
},
],