fix(workflow): optimize input_type validation for loop variables
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from pydantic import Field, BaseModel
|
from pydantic import Field, BaseModel, field_validator
|
||||||
|
|
||||||
from app.core.workflow.nodes.base_config import BaseNodeConfig, VariableType
|
from app.core.workflow.nodes.base_config import BaseNodeConfig, VariableType
|
||||||
from app.core.workflow.nodes.enums import ComparisonOperator, LogicOperator, ValueInputType
|
from app.core.workflow.nodes.enums import ComparisonOperator, LogicOperator, ValueInputType
|
||||||
@@ -27,6 +27,16 @@ class CycleVariable(BaseNodeConfig):
|
|||||||
description="Initial or current value of the loop variable"
|
description="Initial or current value of the loop variable"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@field_validator("input_type", mode="before")
|
||||||
|
@classmethod
|
||||||
|
def lower_input_type(cls, v):
|
||||||
|
if isinstance(v, str):
|
||||||
|
try:
|
||||||
|
return ValueInputType(v.lower())
|
||||||
|
except ValueError:
|
||||||
|
raise ValueError(f"Invalid input_type: {v}")
|
||||||
|
return v
|
||||||
|
|
||||||
|
|
||||||
class ConditionDetail(BaseModel):
|
class ConditionDetail(BaseModel):
|
||||||
operator: ComparisonOperator = Field(
|
operator: ComparisonOperator = Field(
|
||||||
@@ -49,6 +59,16 @@ class ConditionDetail(BaseModel):
|
|||||||
description="Input type of the loop variable"
|
description="Input type of the loop variable"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@field_validator("input_type", mode="before")
|
||||||
|
@classmethod
|
||||||
|
def lower_input_type(cls, v):
|
||||||
|
if isinstance(v, str):
|
||||||
|
try:
|
||||||
|
return ValueInputType(v.lower())
|
||||||
|
except ValueError:
|
||||||
|
raise ValueError(f"Invalid input_type: {v}")
|
||||||
|
return v
|
||||||
|
|
||||||
|
|
||||||
class ConditionsConfig(BaseModel):
|
class ConditionsConfig(BaseModel):
|
||||||
"""Configuration for loop condition evaluation"""
|
"""Configuration for loop condition evaluation"""
|
||||||
|
|||||||
@@ -93,5 +93,5 @@ class HttpErrorHandle(StrEnum):
|
|||||||
|
|
||||||
|
|
||||||
class ValueInputType(StrEnum):
|
class ValueInputType(StrEnum):
|
||||||
VARIABLE = "Variable"
|
VARIABLE = "variable"
|
||||||
CONSTANT = "Constant"
|
CONSTANT = "constant"
|
||||||
|
|||||||
@@ -27,6 +27,16 @@ class ConditionDetail(BaseModel):
|
|||||||
description="Value input type for comparison"
|
description="Value input type for comparison"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@field_validator("input_type", mode="before")
|
||||||
|
@classmethod
|
||||||
|
def lower_input_type(cls, v):
|
||||||
|
if isinstance(v, str):
|
||||||
|
try:
|
||||||
|
return ValueInputType(v.lower())
|
||||||
|
except ValueError:
|
||||||
|
raise ValueError(f"Invalid input_type: {v}")
|
||||||
|
return v
|
||||||
|
|
||||||
|
|
||||||
class ConditionBranchConfig(BaseModel):
|
class ConditionBranchConfig(BaseModel):
|
||||||
"""Configuration for a conditional branch"""
|
"""Configuration for a conditional branch"""
|
||||||
|
|||||||
Reference in New Issue
Block a user