Fix sqlite autocommit cursor transaction control - #8419
Conversation
Assisted-by: Codex:gpt-5.6-sol
📝 WalkthroughWalkthroughSQLite cursor transaction handling now gates implicit DML transactions and script commits on ChangesSQLite autocommit behavior
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/sqlite3 dependencies:
dependent tests: (2 tests)
Legend:
|
There was a problem hiding this comment.
Pull request overview
Aligns RustPython’s sqlite3 cursor transaction behavior with CPython across the three Connection.autocommit modes, ensuring implicit transaction control only occurs under sqlite3.LEGACY_TRANSACTION_CONTROL.
Changes:
- Limit implicit DML
BEGINbehavior inCursor.execute()/Cursor.executemany()to legacy transaction control only. - Limit
Cursor.executescript()’s pre-script implicit commit behavior to legacy transaction control only. - Remove
expectedFailuremarkers from two CPython transaction tests that now pass.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
crates/stdlib/src/_sqlite3.rs |
Gates implicit DML transactions and pre-script implicit commits behind AutocommitMode::Legacy to match CPython semantics. |
Lib/test/test_sqlite3/test_transactions.py |
Removes two @unittest.expectedFailure decorators for executescript autocommit tests that now pass. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
Align sqlite cursor transaction control across the three
Connection.autocommitmodes with CPython.Previously,
execute()andexecutemany()started an implicit transaction before DML statements whenever autocommit was not enabled. This also affectedautocommit=False, even though that mode already manages its transaction through the connection lifecycle.executescript()also committed a pending transaction regardless of the selected autocommit mode. This could close a transaction opened explicitly underautocommit=Trueor the transaction maintained underautocommit=False.Implicit DML
BEGINhandling inexecute()andexecutemany()is now limited tosqlite3.LEGACY_TRANSACTION_CONTROL. The implicit pre-scriptCOMMITinexecutescript()is limited to the same mode, matching CPython.As a result:
autocommit=Falsetransaction management remains the responsibility of the connection lifecycle implemented in Fix sqlite autocommit lifecycle #8387.autocommit=Trueleaves explicit SQL transaction control untouched.sqlite3.LEGACY_TRANSACTION_CONTROLpreserves the existing implicit transaction behavior.Two CPython tests now pass without
expectedFailure:test_autocommit_enabled_executescripttest_autocommit_disabled_executescriptSummary by CodeRabbit