diff --git a/api/core/app/app_config/easy_ui_based_app/dataset/manager.py b/api/core/app/app_config/easy_ui_based_app/dataset/manager.py index 3d857a4e9c0..be538455afb 100644 --- a/api/core/app/app_config/easy_ui_based_app/dataset/manager.py +++ b/api/core/app/app_config/easy_ui_based_app/dataset/manager.py @@ -213,6 +213,11 @@ class DatasetConfigManager: PlanningStrategy.REACT_ROUTER, }: for tool in config.get("agent_mode", {}).get("tools", []): + if not tool: + # Skip malformed empty tool entries; list(tool.keys())[0] + # would otherwise raise IndexError. The sibling convert() + # already guards this with `if len(tool) == 1`. + continue key = list(tool.keys())[0] if key == "dataset": # old style, use tool name as key diff --git a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_dataset_manager.py b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_dataset_manager.py index d5305d2fc0b..e4e4f99c6d4 100644 --- a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_dataset_manager.py +++ b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_dataset_manager.py @@ -318,3 +318,26 @@ class TestIsDatasetExists: return_value=mock_dataset, ) assert not DatasetConfigManager.is_dataset_exists("tenant1", valid_uuid) + + +# ============================== +# extract_dataset_config_for_legacy_compatibility tests +# ============================== + + +class TestExtractDatasetConfigForLegacyCompatibility: + def test_skips_empty_tool_entry(self): + # A malformed empty tool dict in agent_mode.tools must be skipped, not + # crash with `IndexError` on `list(tool.keys())[0]`. The sibling + # convert() already guards this with `if len(tool) == 1`. + config = { + "agent_mode": { + "enabled": True, + "strategy": PlanningStrategy.ROUTER, + "tools": [{}], + } + } + + result = DatasetConfigManager.extract_dataset_config_for_legacy_compatibility("tenant1", AppMode.CHAT, config) + + assert result["agent_mode"]["tools"] == [{}]