Even better transaction support #63
Merged
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 significant improvements to Mayim's transaction system, focusing on simplifying transaction management, fixing rollback bugs, and providing proper connection isolation. The changes refactor how transactions are tracked, enhance the transaction API to support SQL isolation levels, and unify transaction handling across single and multi-executor scenarios. Several files have also been updated for code clarity and maintainability.
Transaction system refactor and improvements:
ContextVarfor tracking transaction state inmayim.base.interface.pywith a simpler instance variable, improving connection isolation and fixing bugs related to transaction rollback. Added methods for setting and clearing the transaction connection. [1] [2]mayim.pyto accept a newisolation_levelparameter, supporting both string and enum values. Added normalization and validation for isolation levels, and ensured the correct propagation to the transaction coordinator. [1] [2]sql/executor.py, so single-executor transactions now use theTransactionCoordinatorinternally. This fixes bugs with rollback/commit and ensures consistent transaction management.transactionmodule with a clean implementation of the transaction coordinator, isolation level enums, and related error classes.Codebase cleanup and clarity:
passstatements for error and default classes to improve readability and maintainability. [1] [2] [3]Other updates:
1.3.0insetup.cfg.postgres/interface.pyto use the new transaction connection tracking.These changes collectively make transaction handling in Mayim more robust, easier to use, and less error-prone, especially in complex or multi-executor scenarios.