Repository navigation
Conversation
Transaction-scoped pg_advisory_xact_lock with str keys hashed by blake2b to a signed bigint, a transaction-local lock_timeout set through a bound set_config value, and SQLSTATE 55P03 mapped to LockTimeoutError. Other drivers raise NotImplementedError; calls outside a transaction raise RuntimeError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Task #3834. Adds transaction-scoped Postgres advisory locks so apps no longer run raw
SET LOCAL lock_timeout/pg_advisory_xact_lockSQL or catch driver exceptions.API
DB.advisory_lock(key, timeout_ms=None, connection=None)andConnection.advisory_lock(key, timeout_ms=None)runpg_advisory_xact_lock. Postgres releases the lock at commit or rollback. There is no session-scoped variant.DB.lock_timeout(timeout_ms, connection=None)/Connection.lock_timeout(timeout_ms)set a transaction-local timeout on its own.strkey is hashed with blake2b (8 bytes, signed big-endian), which is stable across processes and Python/Postgres versions.hashtext()is internal, 32-bit, and has changed before;hash()is randomised per process. Anintkey is used as-is and must fitbigint.0..2147483647and bound throughset_config('lock_timeout', :ms, true). Nothing is interpolated.55P03raisesLockTimeoutError(key, timeout_ms), exported fromfastapi_startkit.masoniteormand chained from the driver error.RuntimeError. Non-Postgres connections raiseNotImplementedError.ADR 060 is added and indexed. 058 is taken by #341 and 059 by the in-progress subquery task. The transaction modules are untouched.
DB.pyadditions sit above the transaction methods to avoid conflicting with #340.Validation
uv run pytest --ignore=tests/masoniteorm/postgres --cov: 3762 passed, coverage 92.77%.tests/masoniteorm/connections/test_advisory_lock.py, 35) cover:55P03mapping and pass-through of other driver errorsNotImplementedErrortests/masoniteorm/postgres/test_advisory_lock.py, 9) passed against a throwawaypostgres:17docker container (POSTGRES_PORT=55434). They cover:pg_locksLockTimeoutErrorand the connection is releasedlock_timeoutreturns to its previous value after the transaction (same backend pid)🤖 Generated with Claude Code