From 22c5d34038c0439c07c7b5d94f5a6737e58c6322 Mon Sep 17 00:00:00 2001 From: ogabrielluiz Date: Mon, 17 Jun 2024 20:18:23 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20(base.py):=20add=20field=5Fvalid?= =?UTF-8?q?ator=20decorator=20to=20validate=20name=20field=20based=20on=20?= =?UTF-8?q?dataType=20in=20SourceHandle=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/base/langflow/graph/edge/base.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/backend/base/langflow/graph/edge/base.py b/src/backend/base/langflow/graph/edge/base.py index f4889bfcc..2a11f82d4 100644 --- a/src/backend/base/langflow/graph/edge/base.py +++ b/src/backend/base/langflow/graph/edge/base.py @@ -1,7 +1,7 @@ from typing import TYPE_CHECKING, Any, List, Optional 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.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." ) + @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): fieldName: str = Field(..., description="Field name for the target handle.")