From 4620669129ccc5baf225e3894d0cf19a660934ad Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 22 Nov 2024 19:05:28 -0300 Subject: [PATCH] fix: Fix flow addition to session and handle IntegrityError for orphaned flows (#4799) * Handle IntegrityError specifically when assigning orphaned flows to superuser * Add missing session.add(flow) to ensure flow is added to the session before commit --- src/backend/base/langflow/services/database/service.py | 1 + src/backend/base/langflow/services/utils.py | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/backend/base/langflow/services/database/service.py b/src/backend/base/langflow/services/database/service.py index ed582ec01..15abe5fac 100644 --- a/src/backend/base/langflow/services/database/service.py +++ b/src/backend/base/langflow/services/database/service.py @@ -187,6 +187,7 @@ class DatabaseService(Service): flow.user_id = superuser.id flow.name = self._generate_unique_flow_name(flow.name, existing_names) existing_names.add(flow.name) + session.add(flow) # Commit changes await session.commit() diff --git a/src/backend/base/langflow/services/utils.py b/src/backend/base/langflow/services/utils.py index f71dba557..974c77795 100644 --- a/src/backend/base/langflow/services/utils.py +++ b/src/backend/base/langflow/services/utils.py @@ -243,9 +243,7 @@ async def initialize_services(*, fix_migration: bool = False) -> None: await setup_superuser(settings_service, session) try: await get_db_service().assign_orphaned_flows_to_superuser() - except Exception as exc: - msg = "Error assigning orphaned flows to the superuser" - logger.exception(msg) - raise RuntimeError(msg) from exc + except sqlalchemy_exc.IntegrityError as exc: + logger.warning(f"Error assigning orphaned flows to the superuser: {exc!s}") await clean_transactions(settings_service, session) await clean_vertex_builds(settings_service, session)