[PR #21207] Revert "bug: fix sequence number may be duplicated when multi-threads running the same workflow #21047" #29596

Closed
opened 2026-02-21 20:45:52 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/21207

State: closed
Merged: Yes


The changes introduced in #21153 are problematic because the FOR UPDATE clause cannot be used with aggregate functions such as MAX() or COALESCE(). PostgreSQL does not allow locking rows when the query involves computed aggregate results instead of actual table rows. This limitation stems from the database's inability to determine which specific rows should be locked under such circumstances.

Here is an excerpt from the error log:

2025-06-19 02:16:27,552 ERROR [_internal.py:97]  Error on request:
Traceback (most recent call last):
  File "/Users/novicelee/pro/dify/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
    self.dialect.do_execute(
  File "/Users/novicelee/pro/dify/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 941, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.FeatureNotSupported: FOR UPDATE is not allowed with aggregate functions

Reverts langgenius/dify#21153
Reopens #21047.

**Original Pull Request:** https://github.com/langgenius/dify/pull/21207 **State:** closed **Merged:** Yes --- The changes introduced in #21153 are problematic because the `FOR UPDATE` clause cannot be used with aggregate functions such as `MAX()` or `COALESCE()`. PostgreSQL does not allow locking rows when the query involves computed aggregate results instead of actual table rows. This limitation stems from the database's inability to determine which specific rows should be locked under such circumstances. Here is an excerpt from the error log: ```bash 2025-06-19 02:16:27,552 ERROR [_internal.py:97] Error on request: Traceback (most recent call last): File "/Users/novicelee/pro/dify/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context self.dialect.do_execute( File "/Users/novicelee/pro/dify/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 941, in do_execute cursor.execute(statement, parameters) psycopg2.errors.FeatureNotSupported: FOR UPDATE is not allowed with aggregate functions ``` Reverts langgenius/dify#21153 Reopens #21047.
yindo added the pull-request label 2026-02-21 20:45:52 -05:00
yindo closed this issue 2026-02-21 20:45:52 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#29596