mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-11 16:08:58 +08:00
fix(validation): improve variable handling and validation (#9578)
This commit is contained in:
parent
495cf58014
commit
740a723072
@ -53,11 +53,11 @@ class BasicVariablesConfigManager:
|
|||||||
VariableEntity(
|
VariableEntity(
|
||||||
type=variable_type,
|
type=variable_type,
|
||||||
variable=variable.get("variable"),
|
variable=variable.get("variable"),
|
||||||
description=variable.get("description", ""),
|
description=variable.get("description") or "",
|
||||||
label=variable.get("label"),
|
label=variable.get("label"),
|
||||||
required=variable.get("required", False),
|
required=variable.get("required", False),
|
||||||
max_length=variable.get("max_length"),
|
max_length=variable.get("max_length"),
|
||||||
options=variable.get("options", []),
|
options=variable.get("options") or [],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ from collections.abc import Sequence
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, Optional
|
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.file import FileExtraConfig, FileTransferMethod, FileType
|
||||||
from core.model_runtime.entities.message_entities import PromptMessageRole
|
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_extensions: Sequence[str] = Field(default_factory=list)
|
||||||
allowed_file_upload_methods: Sequence[FileTransferMethod] = 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):
|
class ExternalDataVariableEntity(BaseModel):
|
||||||
"""
|
"""
|
||||||
|
@ -22,7 +22,7 @@ class WorkflowToolConfigurationUtils:
|
|||||||
if not start_node:
|
if not start_node:
|
||||||
return []
|
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
|
@classmethod
|
||||||
def check_is_synced(
|
def check_is_synced(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user