From 02fdc5e2a47c176f68863229166ffe36fd263080 Mon Sep 17 00:00:00 2001 From: kinglisky Date: Fri, 5 Dec 2025 15:27:18 +0800 Subject: [PATCH] fix: Variable Assigner node silently fails for legacy V1 data format (#28867) --- api/core/workflow/nodes/node_factory.py | 5 +++- .../v1/test_variable_assigner_v1.py | 24 ++++++++++++++++--- .../v2/test_variable_assigner_v2.py | 8 +++---- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/api/core/workflow/nodes/node_factory.py b/api/core/workflow/nodes/node_factory.py index 5fc363257b..c55ad346bf 100644 --- a/api/core/workflow/nodes/node_factory.py +++ b/api/core/workflow/nodes/node_factory.py @@ -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}") diff --git a/api/tests/unit_tests/core/workflow/nodes/variable_assigner/v1/test_variable_assigner_v1.py b/api/tests/unit_tests/core/workflow/nodes/variable_assigner/v1/test_variable_assigner_v1.py index ef23a8f565..c62fc4d8fe 100644 --- a/api/tests/unit_tests/core/workflow/nodes/variable_assigner/v1/test_variable_assigner_v1.py +++ b/api/tests/unit_tests/core/workflow/nodes/variable_assigner/v1/test_variable_assigner_v1.py @@ -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", }, ], diff --git a/api/tests/unit_tests/core/workflow/nodes/variable_assigner/v2/test_variable_assigner_v2.py b/api/tests/unit_tests/core/workflow/nodes/variable_assigner/v2/test_variable_assigner_v2.py index f793341e73..caa36734ad 100644 --- a/api/tests/unit_tests/core/workflow/nodes/variable_assigner/v2/test_variable_assigner_v2.py +++ b/api/tests/unit_tests/core/workflow/nodes/variable_assigner/v2/test_variable_assigner_v2.py @@ -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", }, ],