Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(validation): improve variable handling and validation (#9578)

-LAN-740a72307290
diff --git a/api/core/app/app_config/easy_ui_based_app/variables/manager.py b/api/core/app/app_config/easy_ui_based_app/variables/manager.py
index 126eb0b41ed..2f2445a3363 100644
--- a/api/core/app/app_config/easy_ui_based_app/variables/manager.py
+++ b/api/core/app/app_config/easy_ui_based_app/variables/manager.py
@@ -53,11 +53,11 @@ class BasicVariablesConfigManager:
VariableEntity(
type=variable_type,
variable=variable.get("variable"),
- description=variable.get("description", ""),
+ description=variable.get("description") or "",
label=variable.get("label"),
required=variable.get("required", False),
max_length=variable.get("max_length"),
- options=variable.get("options", []),
+ options=variable.get("options") or [],
)
)
diff --git a/api/core/app/app_config/entities.py b/api/core/app/app_config/entities.py
index d8fa08c0a3e..6c6e342a073 100644
--- a/api/core/app/app_config/entities.py
+++ b/api/core/app/app_config/entities.py
@@ -2,7 +2,7 @@ from collections.abc import Sequence
from enum import Enum
from typing import Any, Optional
-from pydantic import BaseModel, Field
+from pydantic import BaseModel, Field, field_validator
from core.file import FileExtraConfig, FileTransferMethod, FileType
from core.model_runtime.entities.message_entities import PromptMessageRole
@@ -114,6 +114,16 @@ class VariableEntity(BaseModel):
allowed_file_extensions: Sequence[str] = Field(default_factory=list)
allowed_file_upload_methods: Sequence[FileTransferMethod] = Field(default_factory=list)
+ @field_validator("description", mode="before")
+ @classmethod
+ def convert_none_description(cls, v: Any) -> str:
+ return v or ""
+
+ @field_validator("options", mode="before")
+ @classmethod
+ def convert_none_options(cls, v: Any) -> Sequence[str]:
+ return v or []
+
class ExternalDataVariableEntity(BaseModel):
"""
diff --git a/api/core/tools/utils/workflow_configuration_sync.py b/api/core/tools/utils/workflow_configuration_sync.py
index 3ea07b75aa4..d92bfb9b90a 100644
--- a/api/core/tools/utils/workflow_configuration_sync.py
+++ b/api/core/tools/utils/workflow_configuration_sync.py
@@ -22,7 +22,7 @@ class WorkflowToolConfigurationUtils:
if not start_node:
return []
- return [VariableEntity(**variable) for variable in start_node.get("data", {}).get("variables", [])]
+ return [VariableEntity.model_validate(variable) for variable in start_node.get("data", {}).get("variables", [])]
@classmethod
def check_is_synced(