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
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-11-22 19:05:28 -03:00 committed by GitHub
commit 4620669129
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 4 deletions

View file

@ -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()

View file

@ -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)