From 7193bb44888535b6e17f823e644a8de64d96f3e4 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 20 Jul 2023 15:38:22 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(custom=5Fcomponent.py):=20fi?= =?UTF-8?q?x=20session=20context=20and=20add=20error=20handling=20for=20fl?= =?UTF-8?q?ow=20not=20found?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/interface/custom/custom_component.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/interface/custom/custom_component.py b/src/backend/langflow/interface/custom/custom_component.py index 2b0f1f342..233d99186 100644 --- a/src/backend/langflow/interface/custom/custom_component.py +++ b/src/backend/langflow/interface/custom/custom_component.py @@ -133,8 +133,10 @@ class CustomComponent(Component): def load_flow(self, flow_id: UUID = None): from langflow.processing.process import build_sorted_vertices_with_caching - session = next(get_session()) - data_graph = flow.data if (flow := session.get(Flow, flow_id)) else None + with get_session() as session: + data_graph = flow.data if (flow := session.get(Flow, flow_id)) else None + if not data_graph: + raise ValueError(f"Flow {flow_id} not found") return build_sorted_vertices_with_caching(data_graph) def build(self):