mirror of
https://github.com/langgenius/dify.git
synced 2026-11-10 21:35:45 +08:00
fix: reject empty user_input_form items instead of raising IndexError (#37671)
Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Co-authored-by: Byron Wang <byron@dify.ai>
This commit is contained in:
1 parent
8e689e868b
commit
214cdfd6fa
2 files changed
+18
No files matched your search
@@ -45,6 +45,8 @@ class BasicVariablesConfigManager:
|
||||
|
||||
# variables and external_data_tools
|
||||
for variables in config.get("user_input_form", []):
|
||||
if not variables:
|
||||
continue
|
||||
variable_type = list(variables.keys())[0]
|
||||
if variable_type == VariableEntityType.EXTERNAL_DATA_TOOL:
|
||||
variable = variables[variable_type]
|
||||
@@ -112,6 +114,8 @@ class BasicVariablesConfigManager:
|
||||
|
||||
variables = []
|
||||
for item in config["user_input_form"]:
|
||||
if not item:
|
||||
raise ValueError("Each item in user_input_form must be a non-empty object")
|
||||
key = list(item.keys())[0]
|
||||
# if key not in {"text-input", "select", "paragraph", "number", "external_data_tool"}:
|
||||
if key not in {
|
||||
|
||||
@@ -70,6 +70,14 @@ class TestBasicVariablesConfigManagerConvert:
|
||||
assert len(variables) == 2
|
||||
assert len(external) == 1
|
||||
|
||||
def test_convert_empty_form_item_skipped(self):
|
||||
config = {"user_input_form": [{}]}
|
||||
|
||||
variables, external = BasicVariablesConfigManager.convert(config)
|
||||
|
||||
assert variables == []
|
||||
assert external == []
|
||||
|
||||
def test_convert_external_data_tool_without_config_skipped(self):
|
||||
config = {
|
||||
"user_input_form": [
|
||||
@@ -112,6 +120,12 @@ class TestValidateVariablesAndSetDefaults:
|
||||
):
|
||||
BasicVariablesConfigManager.validate_variables_and_set_defaults(config)
|
||||
|
||||
def test_validate_empty_form_item_raises(self):
|
||||
config = {"user_input_form": [{}]}
|
||||
|
||||
with pytest.raises(ValueError, match="Each item in user_input_form must be a non-empty object"):
|
||||
BasicVariablesConfigManager.validate_variables_and_set_defaults(config)
|
||||
|
||||
def test_validate_missing_label_raises(self):
|
||||
config = {"user_input_form": [{VariableEntityType.TEXT_INPUT: {"variable": "name"}}]}
|
||||
|
||||
|
||||
Reference in new issue
Block a user