From 2f9932da6dd32ec3ea71b12f2e61bb5509700287 Mon Sep 17 00:00:00 2001 From: ogabrielluiz Date: Tue, 11 Jun 2024 22:57:14 -0300 Subject: [PATCH] refactor: Update Component class to handle missing inputs in custom components Handle the case where inputs are missing in custom components by setting them to None and logging a warning. This ensures compatibility with the latest version of the langflow library and improves code robustness. --- .../langflow/custom/custom_component/component.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/backend/base/langflow/custom/custom_component/component.py b/src/backend/base/langflow/custom/custom_component/component.py index e6308da04..79035de24 100644 --- a/src/backend/base/langflow/custom/custom_component/component.py +++ b/src/backend/base/langflow/custom/custom_component/component.py @@ -60,6 +60,10 @@ class Component(CustomComponent): if key in self.__dict__: raise ValueError(f"Key {key} already exists in {self.__class__.__name__}") setattr(self, key, value) + for input_ in self.inputs: + if input_.name not in params: + setattr(self, input_.name, None) + logger.warning(f"Input {input_.name} not found in arguments") self._arguments = params def _set_outputs(self, outputs: List[dict]): @@ -141,5 +145,8 @@ class Component(CustomComponent): return build_config def _get_field_order(self): - inputs = self.template_config["inputs"] - return [field.name for field in inputs] + try: + inputs = self.template_config["inputs"] + return [field.name for field in inputs] + except KeyError: + return []