mirror of
https://github.com/langgenius/dify.git
synced 2026-06-22 19:21:13 +08:00
fix: skip empty tool entries in legacy dataset config extraction (#37669)
Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
This commit is contained in:
parent
44464c8c63
commit
3a3ad6ad7c
@ -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
|
||||
|
||||
@ -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"] == [{}]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user