From 082a61eadd6cee6f30fef287205c35395bfc4d45 Mon Sep 17 00:00:00 2001 From: gustavoschaedler Date: Mon, 31 Jul 2023 23:07:02 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(custom=5Fcomponent.py):=20fi?= =?UTF-8?q?x=20error=20message=20typo=20in=20CustomComponent=20class=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(directory=5Freader.py):=20fix=20error=20mess?= =?UTF-8?q?age=20typo=20in=20DirectoryReader=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../langflow/interface/custom/custom_component.py | 15 +++++++++++---- .../langflow/interface/custom/directory_reader.py | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/backend/langflow/interface/custom/custom_component.py b/src/backend/langflow/interface/custom/custom_component.py index 0b6f0a732..06a4f4d7c 100644 --- a/src/backend/langflow/interface/custom/custom_component.py +++ b/src/backend/langflow/interface/custom/custom_component.py @@ -2,6 +2,7 @@ from typing import Any, Callable, List, Optional from fastapi import HTTPException from langflow.interface.custom.constants import CUSTOM_COMPONENT_SUPPORTED_TYPES from langflow.interface.custom.component import Component +from langflow.interface.custom.directory_reader import DirectoryReader from langflow.utils import validate @@ -38,12 +39,18 @@ class CustomComponent(Component, extra=Extra.allow): }, ) - # TODO: Create the logic to validate what the Custom Component - # should have as a prerequisite to be able to execute - return True + reader = DirectoryReader("", False) + if reader.is_type_hint_used_but_not_imported("Optional", code): + raise HTTPException( + status_code=400, + detail={ + "error": "Type hint Error", + "traceback": "Name type hint 'Optional' is not defined", + }, + ) def is_check_valid(self) -> bool: - return self._class_template_validation(self.code) if self.code else False + return self._class_template_validation(self.code) def get_code_tree(self, code: str): return super().get_code_tree(code) diff --git a/src/backend/langflow/interface/custom/directory_reader.py b/src/backend/langflow/interface/custom/directory_reader.py index d24dbd1ab..2f448e319 100644 --- a/src/backend/langflow/interface/custom/directory_reader.py +++ b/src/backend/langflow/interface/custom/directory_reader.py @@ -196,7 +196,7 @@ class DirectoryReader: elif not self.validate_build(file_content): return False, "Missing build function" elif self.is_type_hint_used_but_not_imported("Optional", file_content): - return False, "Name hint type 'Optional' is not defined" + return False, "Name type hint 'Optional' is not defined" else: if self.compress_code_field: file_content = str(StringCompressor(file_content).compress_string())