Skip to content

Commit

Permalink
fix: Fix flow addition to session and handle IntegrityError for orpha…
Browse files Browse the repository at this point in the history
…ned flows (langflow-ai#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
  • Loading branch information
ogabrielluiz authored and diogocabral committed Nov 26, 2024
1 parent 2e63f5b commit 2253644
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/backend/base/langflow/services/database/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ async def assign_orphaned_flows_to_superuser(self) -> None:
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()
Expand Down
6 changes: 2 additions & 4 deletions src/backend/base/langflow/services/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 2253644

Please sign in to comment.