Conversation
This commit adds comprehensive transaction management improvements to Mayim: Core Features: - New transaction coordinator system for managing cross-executor transactions - Two-phase commit protocol support for distributed transactions - Proper connection sharing across executors in global transactions - Transaction state machine (PENDING, ACTIVE, COMMITTED, ROLLED_BACK) API Enhancements: - New explicit transaction API: txn = await Mayim.transaction(); await txn.begin() - Backward compatible with existing context manager pattern - Support for mixing executor classes and instances in transactions - Optional use_2pc parameter for enabling two-phase commit Bug Fixes: - Fixed DSN parsing to handle missing ports with sensible defaults - Fixed connection sharing across executors with same DSN - Fixed transaction context propagation through ContextVars - Fixed nested transaction handling (now properly no-ops when in global transaction) Testing: - Added comprehensive test suite for transaction failures - Added tests for new explicit transaction API - Added advanced transaction tests (deadlock detection, ACID compliance, etc.) - All tests passing except unimplemented optional features (marked as xfail) Technical Details: - GlobalTransactionContext manages connections across multiple executors - PoolRegistry ensures executors with same DSN share pool instances - Transaction coordinator handles begin/commit/rollback lifecycle - Proper cleanup and error handling throughout 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Exclude Claude Code session files from version control. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…m into better-transaction-support
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.
This pull request introduces several major improvements to the Mayim library, focusing on enhanced connection pool management, improved transaction coordination, and expanded configuration options. The most significant changes include the introduction of a shared pool registry to prevent duplicate connections, support for connection pool sizing, a more flexible transaction API (including two-phase commit and timeouts), and compatibility updates for newer Python versions.
Connection Pool Management and Sizing:
PoolRegistryto ensure that executors using the same DSN share a single pool instance, preventing duplicate connections and enabling proper transaction coordination (src/mayim/registry.py,src/mayim/mayim.py,tests/conftest.py). [1] [2] [3] [4]min_sizeandmax_sizeparameters inBaseInterfaceand its subclasses, and ensured these are passed through the registry and pool constructors (src/mayim/base/interface.py,src/mayim/lazy/interface.py,src/mayim/sql/postgres/interface.py,src/mayim/mayim.py). [1] [2] [3] [4] [5] [6] [7]Transaction Coordination and API Improvements:
Mayim.transactionAPI to support both old and new usage styles, added options for two-phase commit (use_2pc) and transaction timeouts, and introduced a wrapper for backward compatibility. The new API ensures only registered SQL executors are used and supports both context manager and awaitable usage (src/mayim/mayim.py).SQLExecutorto honor global transaction context, ensuring that rollbacks and transaction context managers interact correctly with coordinated transactions (src/mayim/sql/executor.py). [1] [2]Python Compatibility and Miscellaneous:
setup.cfgand bumped the package version to 1.2.0. [1] [2]src/mayim/exception.py,src/mayim/extension/quart_extension.py,src/mayim/extension/starlette_extension.py,src/mayim/base/executor.py,src/mayim/base/interface.py,src/mayim/lazy/interface.py). [1] [2] [3] [4] [5]These changes collectively modernize the codebase, improve resource management, and provide more robust transactional guarantees for multi-database operations.