fix(storage): use SAVEPOINT in initialize_concurrency_limit_to_default to fix PostgreSQL crash#33601
Open
Vamsi-klu wants to merge 1 commit into
Open
Conversation
Contributor
…t to fix PostgreSQL crash On PostgreSQL, a failed INSERT within a transaction aborts the entire transaction. The subsequent UPDATE in the except block then fails with InFailedSqlTransaction. This is a production blocker for any deployment using pool= on PostgreSQL. Fix: wrap the INSERT in conn.begin_nested() (a SAVEPOINT). On IntegrityError only the savepoint is rolled back, not the whole transaction, allowing the UPDATE to succeed. Works for both SQLite and PostgreSQL. Fixes: dagster-io#33552 Co-Authored-By: codingrealitylabs <codingrealitylabs@users.noreply.github.com> Co-Authored-By: girlcoder-gaming <girlcoder-gaming@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ad73020 to
f48a938
Compare
f48a938 to
69da85d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary & Motivation
Fixes #33552
Production blocker:
SqlEventLogStorage.initialize_concurrency_limit_to_default()crashes on PostgreSQL when the concurrency key already exists in the database. This makes it impossible to run any asset that uses thepool=parameter on PostgreSQL deployments when a race condition or retry causes the INSERT to find an existing row.The bug affects all PostgreSQL-backed Dagster deployments (Azure Database for PostgreSQL, AWS RDS, etc.) using pool-based concurrency limits. The only workaround is manually setting pool limits through the UI.
Root Cause
The method uses an INSERT-then-catch-IntegrityError-then-UPDATE pattern:
On PostgreSQL, a failed INSERT statement aborts the entire transaction. All subsequent statements fail with
InFailedSqlTransactionuntil aROLLBACK. This is fundamental PostgreSQL behavior — unlike SQLite where failed statements don't invalidate the transaction.The bug exists in both code paths:
has_default_pool_limit_col=True— INSERT fails, UPDATE failshas_default_pool_limit_col=False— INSERT fails,_allocate_concurrency_slotsfailsTrigger Scenario
A race condition (concurrent runs, or retry after partial failure where the row was committed by a different process) causes the INSERT to find the row already present.
Fix
Wrapped the INSERT in
conn.begin_nested()(SAVEPOINT). On IntegrityError, only the savepoint is rolled back — the outer transaction proceeds. Applied to both code paths. This pattern is already used elsewhere in the codebase (store_asset_event,add_dynamic_partitions).Test Plan
test_initialize_concurrency_limit_to_default_idempotent(double-call + update)test_default_concurrencytest_changing_default_concurrency_keymake ruffError Before Fix
Changelog
Fixed a crash in
initialize_concurrency_limit_to_defaulton PostgreSQL when the concurrency key already exists. The method now uses a SAVEPOINT to handle the INSERT conflict gracefully.🤖 Generated with Claude Code