From 1dcb71b952f3b05a7347a13aace2a021194febc1 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 5 Jul 2023 17:21:03 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(base.py):=20handle=20case=20?= =?UTF-8?q?when=20base=5Ftype=20is=20None=20to=20avoid=20ValueError=20The?= =?UTF-8?q?=20code=20now=20checks=20if=20the=20`base=5Ftype`=20attribute?= =?UTF-8?q?=20is=20None=20before=20attempting=20to=20instantiate=20a=20cla?= =?UTF-8?q?ss.=20If=20`base=5Ftype`=20is=20None,=20a=20ValueError=20is=20r?= =?UTF-8?q?aised=20with=20a=20descriptive=20error=20message.=20This=20fix?= =?UTF-8?q?=20prevents=20potential=20errors=20when=20the=20`base=5Ftype`?= =?UTF-8?q?=20is=20not=20found=20for=20a=20given=20node.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/graph/vertex/base.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/graph/vertex/base.py b/src/backend/langflow/graph/vertex/base.py index 193684cb6..ab3abec46 100644 --- a/src/backend/langflow/graph/vertex/base.py +++ b/src/backend/langflow/graph/vertex/base.py @@ -1,5 +1,6 @@ from langflow.interface.initialize import loading from langflow.interface.listing import ALL_TYPES_DICT +from langflow.utils.constants import DIRECT_TYPES from langflow.utils.logger import logger from langflow.utils.util import sync_to_async @@ -110,8 +111,14 @@ class Vertex: file_path = value.get("file_path") params[key] = file_path - elif value.get("type") in ["str", "prompt"] and params.get(key) is None: + elif value.get("type") in DIRECT_TYPES and params.get(key) is None: params[key] = value.get("value") + + if not value.get("required") and params.get(key) is None: + if value.get("default"): + params[key] = value.get("default") + else: + params.pop(key, None) # Add _type to params self.params = params @@ -176,6 +183,8 @@ class Vertex: # and return the instance try: + if self.base_type is None: + raise ValueError(f"Base type for node {self.vertex_type} not found") result = loading.instantiate_class( node_type=self.vertex_type, base_type=self.base_type,