mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 04:26:30 +08:00
fix(trigger): improve error handling in DraftWorkflowTriggerNodeApi and update input class naming
- Removed specific exception handling for ValueError and PluginInvokeError in `DraftWorkflowTriggerNodeApi`, allowing a more general exception to be raised. - Renamed `PluginTriggerInput` to `TriggerEventInput` in `TriggerEventNodeData` for better clarity and consistency. - Updated validation logic in `TriggerEventInput` to ensure correct type checks for input values.
This commit is contained in:
parent
1c17a16830
commit
d4516e942c
@ -12,30 +12,32 @@ from core.workflow.nodes.trigger_plugin.exc import TriggerEventParameterError
|
|||||||
class TriggerEventNodeData(BaseNodeData):
|
class TriggerEventNodeData(BaseNodeData):
|
||||||
"""Plugin trigger node data"""
|
"""Plugin trigger node data"""
|
||||||
|
|
||||||
class PluginTriggerInput(BaseModel):
|
class TriggerEventInput(BaseModel):
|
||||||
value: Union[Any, list[str]]
|
value: Union[Any, list[str]]
|
||||||
type: Literal["mixed", "variable", "constant"]
|
type: Literal["mixed", "variable", "constant"]
|
||||||
|
|
||||||
@field_validator("type", mode="before")
|
@field_validator("type", mode="before")
|
||||||
@classmethod
|
@classmethod
|
||||||
def check_type(cls, value, validation_info: ValidationInfo):
|
def check_type(cls, value, validation_info: ValidationInfo):
|
||||||
typ = value
|
type = value
|
||||||
value = validation_info.data.get("value")
|
value = validation_info.data.get("value")
|
||||||
|
|
||||||
if value is None:
|
if value is None:
|
||||||
return typ
|
return type
|
||||||
|
|
||||||
if typ == "mixed" and not isinstance(value, str):
|
if type == "mixed" and not isinstance(value, str):
|
||||||
raise ValueError("value must be a string")
|
raise ValueError("value must be a string")
|
||||||
elif typ == "variable":
|
|
||||||
|
if type == "variable":
|
||||||
if not isinstance(value, list):
|
if not isinstance(value, list):
|
||||||
raise ValueError("value must be a list")
|
raise ValueError("value must be a list")
|
||||||
for val in value:
|
for val in value:
|
||||||
if not isinstance(val, str):
|
if not isinstance(val, str):
|
||||||
raise ValueError("value must be a list of strings")
|
raise ValueError("value must be a list of strings")
|
||||||
elif typ == "constant" and not isinstance(value, str | int | float | bool | dict):
|
|
||||||
|
if type == "constant" and not isinstance(value, str | int | float | bool | dict | list):
|
||||||
raise ValueError("value must be a string, int, float, bool or dict")
|
raise ValueError("value must be a string, int, float, bool or dict")
|
||||||
return typ
|
return type
|
||||||
|
|
||||||
title: str
|
title: str
|
||||||
desc: Optional[str] = None
|
desc: Optional[str] = None
|
||||||
@ -44,7 +46,7 @@ class TriggerEventNodeData(BaseNodeData):
|
|||||||
event_name: str = Field(..., description="Event name")
|
event_name: str = Field(..., description="Event name")
|
||||||
subscription_id: str = Field(..., description="Subscription ID")
|
subscription_id: str = Field(..., description="Subscription ID")
|
||||||
plugin_unique_identifier: str = Field(..., description="Plugin unique identifier")
|
plugin_unique_identifier: str = Field(..., description="Plugin unique identifier")
|
||||||
event_parameters: Mapping[str, PluginTriggerInput] = Field(default_factory=dict, description="Trigger parameters")
|
event_parameters: Mapping[str, TriggerEventInput] = Field(default_factory=dict, description="Trigger parameters")
|
||||||
|
|
||||||
# Error handling
|
# Error handling
|
||||||
error_strategy: Optional[ErrorStrategy] = Field(
|
error_strategy: Optional[ErrorStrategy] = Field(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user