From a6dfe3988231b84b6dfc8f49ef7baeb2958412fa Mon Sep 17 00:00:00 2001 From: ogabrielluiz Date: Fri, 7 Jun 2024 11:15:53 -0300 Subject: [PATCH] refactor: add session_id to vertices without it in build_and_cache_graph_from_db --- src/backend/base/langflow/api/utils.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/backend/base/langflow/api/utils.py b/src/backend/base/langflow/api/utils.py index cc38b474a..2d24d62ee 100644 --- a/src/backend/base/langflow/api/utils.py +++ b/src/backend/base/langflow/api/utils.py @@ -204,16 +204,18 @@ def format_elapsed_time(elapsed_time: float) -> str: return f"{minutes} {minutes_unit}, {seconds} {seconds_unit}" -async def build_and_cache_graph_from_db( - flow_id: str, - session: Session, - chat_service: "ChatService", -): +async def build_and_cache_graph_from_db(flow_id: str, session: Session, chat_service: "ChatService"): """Build and cache the graph.""" flow: Optional[Flow] = session.get(Flow, flow_id) if not flow or not flow.data: raise ValueError("Invalid flow ID") graph = Graph.from_payload(flow.data, flow_id) + for vertex_id in graph._has_session_id_vertices: + vertex = graph.get_vertex(vertex_id) + if vertex is None: + raise ValueError(f"Vertex {vertex_id} not found") + if vertex._raw_params.get("session_id") is None: + vertex.update_raw_params({"session_id": flow_id}) await chat_service.set_cache(flow_id, graph) return graph @@ -317,3 +319,4 @@ def parse_exception(exc): if hasattr(exc, "body"): return exc.body["message"] return str(exc) + return str(exc)