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:
Yufeng He 2026-06-21 15:32:15 +08:00 committed by GitHub
parent 44464c8c63
commit 3a3ad6ad7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 0 deletions

View File

@ -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

View File

@ -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"] == [{}]