📝 (base.py): add field_validator decorator to validate name field based on dataType in SourceHandle class
This commit is contained in:
parent
84e1d39b71
commit
22c5d34038
1 changed files with 12 additions and 1 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
from typing import TYPE_CHECKING, Any, List, Optional
|
from typing import TYPE_CHECKING, Any, List, Optional
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field, field_validator
|
||||||
|
|
||||||
from langflow.schema.schema import INPUT_FIELD_NAME
|
from langflow.schema.schema import INPUT_FIELD_NAME
|
||||||
from langflow.services.monitor.utils import log_message
|
from langflow.services.monitor.utils import log_message
|
||||||
|
|
@ -19,6 +19,17 @@ class SourceHandle(BaseModel):
|
||||||
default_factory=list, description="List of output types for the source handle."
|
default_factory=list, description="List of output types for the source handle."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@field_validator("name", mode="before")
|
||||||
|
@classmethod
|
||||||
|
def validate_name(cls, v, _info):
|
||||||
|
if _info.data["dataType"] == "GroupNode":
|
||||||
|
# 'OpenAIModel-u4iGV_text_output'
|
||||||
|
splits = v.split("_", 1)
|
||||||
|
if len(splits) != 2:
|
||||||
|
raise ValueError(f"Invalid source handle name {v}")
|
||||||
|
v = splits[1]
|
||||||
|
return v
|
||||||
|
|
||||||
|
|
||||||
class TargetHandle(BaseModel):
|
class TargetHandle(BaseModel):
|
||||||
fieldName: str = Field(..., description="Field name for the target handle.")
|
fieldName: str = Field(..., description="Field name for the target handle.")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue