Repository navigation
fix(#392): handle join_txn_mode for version_session - #393
skissane-medallia wants to merge 1 commit into
Conversation
- SQLA 2.0 introduced new session param called `join_transaction_mode` which changes the behaviour of how existing transactions are handled - When using a Connection with an existing SAVEPOINT: `SQLA-1.4`: the Session would propagate both commit() and rollback() calls to the underlying transaction. `SQLA-2.0`: use join_transaction_mode=control_fully to replicate the same behaviour. - When using a Connection without an existing SAVEPOINT: `SQLA-1.4`: the Session would propagate only rollback() calls to the underlying transaction. `SQLA-2.0`: use join_transaction_mode=rollback_only to replicate the same behaviour. - use `rollback_only` mode while creation of version_session, as it is using an existing connection, and we are never doing a commit() on it. Cherry-picked by @skissane-medallia from corridor/sqlalchemy-history#122 by @ashish16052 Closes sqlalchemy-continuum#392
|
@coderabbitai full review |
✅ Action performedFull review finished. |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe unit of work now creates version sessions through a shared helper. The helper selects rollback-only transaction joining when supported and falls back to connection binding. A regression test checks version creation during a nested transaction while treating ChangesVersion session handling
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Low Suggested reviewers: Merge Risk: ⚪ Minimal · up to The change is focused on version-session handling during nested transactions and adds a regression check. Based on the available evidence, no concrete merge-blocking risk remains. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change keeps history writes on the caller’s database connection and adds no evident new access path. Its compatibility fallback could, under an unexpected error, use different rollback behavior; failure and retry behavior remains unverified. Retained concerns
Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
|
|
||
| def create_version_session(self, session): | ||
| """ | ||
| In SQLA-2.0, when using an existing connection with savepoint, Set join_transaction_mode="rollback_only" |
There was a problem hiding this comment.
Docstring exceeds line limit The new docstring exceeds the repository’s required 88-character line length. Please wrap it before merging.
| In SQLA-2.0, when using an existing connection with savepoint, Set join_transaction_mode="rollback_only" | |
| In SQLA-2.0, when using an existing connection with savepoint, Set | |
| join_transaction_mode="rollback_only" |
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| try: | ||
| return sa.orm.session.Session( | ||
| bind=session.connection(), join_transaction_mode='rollback_only' | ||
| ) | ||
| except TypeError: | ||
| return sa.orm.session.Session(bind=session.connection()) |
There was a problem hiding this comment.
Fallback retries unrelated errors The
TypeError handler also catches errors from session.connection(), not just an unsupported SQLAlchemy 1.4 keyword. If connection acquisition raises an unrelated TypeError, the fallback calls it again and can obscure the original failure. Check compatibility before constructing the version session, and obtain the connection once.
|
@josecsotomorales anything blocking this being merged? We're moving a large test suite over to transactions that roll-back (using |
|
We don't support SQLAlchemy 1.4 any more, so the fallback behaviour is unnecessary (and too broad, as greptile points out). So the real question is whether our default Can you justify making this change the default, or should it be an initialisation argument? |
Description
Ported corridor/sqlalchemy-history#122 fix from sqlalchemy-history fork to this project
Fixes: #392
Description by fix original author (@ashish16052):
SQLA 2.0 introduced new session param called
join_transaction_modewhich changes the behaviour of how existing transactions are handledWhen using a Connection with an existing SAVEPOINT:
SQLA-1.4: the Session would propagate both commit() and rollback() calls to the underlying transaction.SQLA-2.0: use join_transaction_mode=control_fully to replicate the same behaviour.When using a Connection without an existing SAVEPOINT:
SQLA-1.4: the Session would propagate only rollback() calls to the underlying transaction.SQLA-2.0: use join_transaction_mode=rollback_only to replicate the same behaviour.use
rollback_onlymode while creation of version_session, as it is using an existing connection, and we are never doing a commit() on it.Checklist
This pull request is:
must include a complete example of the issue.
Fixes: #<issue number>in the commit messagemust include a complete example of how the feature would look.
Summary by CodeRabbit