From 699152c48f3c81ef5e924a6da95eb536e99958de Mon Sep 17 00:00:00 2001 From: QuantumGhost Date: Thu, 19 Jun 2025 11:25:10 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"bug:=20fix=20sequence=20number=20may?= =?UTF-8?q?=20be=20duplicated=20when=20multi-threads=20running=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 918bb9a2f7de552a2d7f04797c4bc78c38f08c2c. --- .../sqlalchemy_workflow_execution_repository.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/api/core/repositories/sqlalchemy_workflow_execution_repository.py b/api/core/repositories/sqlalchemy_workflow_execution_repository.py index f82562a498..e5ead9dc56 100644 --- a/api/core/repositories/sqlalchemy_workflow_execution_repository.py +++ b/api/core/repositories/sqlalchemy_workflow_execution_repository.py @@ -151,17 +151,12 @@ class SQLAlchemyWorkflowExecutionRepository(WorkflowExecutionRepository): existing = session.scalar(select(WorkflowRun).where(WorkflowRun.id == domain_model.id_)) if not existing: # For new records, get the next sequence number - # in case multiple executions are created concurrently, use for update - stmt = ( - select(func.coalesce(func.max(WorkflowRun.sequence_number), 0) + 1) - .where( - WorkflowRun.app_id == self._app_id, - WorkflowRun.tenant_id == self._tenant_id, - ) - .with_for_update() + stmt = select(func.max(WorkflowRun.sequence_number)).where( + WorkflowRun.app_id == self._app_id, + WorkflowRun.tenant_id == self._tenant_id, ) - next_seq = session.scalar(stmt) - db_model.sequence_number = int(next_seq) if next_seq is not None else 1 + max_sequence = session.scalar(stmt) + db_model.sequence_number = (max_sequence or 0) + 1 else: # For updates, keep the existing sequence number db_model.sequence_number = existing.sequence_number