From e13a3ca800c5b4c102ab4d3b3521ff43a532bfa1 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 9 Jul 2025 16:17:50 -0300 Subject: [PATCH] fix: Ensure flow_id is not None before logging vertex build details (#8954) * fix: Update log_vertex_build to accept UUID for flow_id and improve error handling * Changed flow_id type from str to str | UUID for better type safety. * Added error handling to raise a ValueError if flow_id is invalid, enhancing robustness of the logging function. * fix: Ensure flow_id is not None before logging vertex build details * Updated log_vertex_build call to check if flow_id is not None, enhancing robustness and preventing potential errors when flow_id is absent. --- src/backend/base/langflow/graph/graph/base.py | 17 +++++++++-------- src/backend/base/langflow/graph/utils.py | 10 ++++++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/backend/base/langflow/graph/graph/base.py b/src/backend/base/langflow/graph/graph/base.py index b66c22ac2..e5986fcb9 100644 --- a/src/backend/base/langflow/graph/graph/base.py +++ b/src/backend/base/langflow/graph/graph/base.py @@ -1689,14 +1689,15 @@ class Graph: t.cancel() raise result if isinstance(result, VertexBuildResult): - await log_vertex_build( - flow_id=self.flow_id or "", - vertex_id=result.vertex.id, - valid=result.valid, - params=result.params, - data=result.result_dict, - artifacts=result.artifacts, - ) + if self.flow_id is not None: + await log_vertex_build( + flow_id=self.flow_id, + vertex_id=result.vertex.id, + valid=result.valid, + params=result.params, + data=result.result_dict, + artifacts=result.artifacts, + ) vertices.append(result.vertex) else: diff --git a/src/backend/base/langflow/graph/utils.py b/src/backend/base/langflow/graph/utils.py index e35d6faed..cac41a6a2 100644 --- a/src/backend/base/langflow/graph/utils.py +++ b/src/backend/base/langflow/graph/utils.py @@ -166,7 +166,7 @@ async def log_transaction( async def log_vertex_build( *, - flow_id: str, + flow_id: str | UUID, vertex_id: str, valid: bool, params: Any, @@ -181,9 +181,15 @@ async def log_vertex_build( try: if not get_settings_service().settings.vertex_builds_storage_enabled: return + try: + if isinstance(flow_id, str): + flow_id = UUID(flow_id) + except ValueError: + msg = f"Invalid flow_id passed to log_vertex_build: {flow_id!r}(type: {type(flow_id)})" + raise ValueError(msg) from None vertex_build = VertexBuildBase( - flow_id=flow_id if isinstance(flow_id, UUID) else UUID(flow_id), + flow_id=flow_id, id=vertex_id, valid=valid, params=str(params) if params else None,