Skip to content

Fix sqlite autocommit cursor transaction control - #8419

Merged
youknowone merged 1 commit into
RustPython:mainfrom
teddygood:fix-sqlite-autocommit-cursor-control
Aug 1, 2026
Merged

Fix sqlite autocommit cursor transaction control#8419
youknowone merged 1 commit into
RustPython:mainfrom
teddygood:fix-sqlite-autocommit-cursor-control

Conversation

@teddygood

@teddygood teddygood commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Align sqlite cursor transaction control across the three Connection.autocommit modes with CPython.

Previously, execute() and executemany() started an implicit transaction before DML statements whenever autocommit was not enabled. This also affected autocommit=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 under autocommit=True or the transaction maintained under autocommit=False.

Implicit DML BEGIN handling in execute() and executemany() is now limited to sqlite3.LEGACY_TRANSACTION_CONTROL. The implicit pre-script COMMIT in executescript() is limited to the same mode, matching CPython.

As a result:

  • autocommit=False transaction management remains the responsibility of the connection lifecycle implemented in Fix sqlite autocommit lifecycle #8387.
  • autocommit=True leaves explicit SQL transaction control untouched.
  • sqlite3.LEGACY_TRANSACTION_CONTROL preserves the existing implicit transaction behavior.

Two CPython tests now pass without expectedFailure:

  • test_autocommit_enabled_executescript
  • test_autocommit_disabled_executescript

Summary by CodeRabbit

  • Bug Fixes
    • Refined transaction handling for database modification statements and scripts.
    • Prevented unintended implicit transactions and commits when using non-legacy autocommit modes.
    • Preserved expected legacy autocommit behavior for configured connections.

Assisted-by: Codex:gpt-5.6-sol
Copilot AI review requested due to automatic review settings July 30, 2026 17:49
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

SQLite cursor transaction handling now gates implicit DML transactions and script commits on AutocommitMode::Legacy in execute, executemany, and executescript.

Changes

SQLite autocommit behavior

Layer / File(s) Summary
Legacy autocommit transaction gating
crates/stdlib/src/_sqlite3.rs
Cursor.execute and Cursor.executemany begin implicit DML transactions only in legacy mode, while Cursor.executescript performs its implicit commit only in legacy mode.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: ever0de, youknowone

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR changes the legacy-only implicit BEGIN/COMMIT behavior needed to align cursor transaction control with CPython.
Out of Scope Changes check ✅ Passed The summary shows only targeted sqlite3 transaction-control edits, with no unrelated changes evident.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: SQLite cursor transaction control behavior for autocommit modes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[x] lib: cpython/Lib/sqlite3
[x] test: cpython/Lib/test/test_sqlite3 (TODO: 63)

dependencies:

  • sqlite3

dependent tests: (2 tests)

  • sqlite3: test_dbm_sqlite3 test_sqlite3

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 BEGIN behavior in Cursor.execute() / Cursor.executemany() to legacy transaction control only.
  • Limit Cursor.executescript()’s pre-script implicit commit behavior to legacy transaction control only.
  • Remove expectedFailure markers 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.

@teddygood

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@teddygood
teddygood marked this pull request as ready for review July 30, 2026 18:41
@youknowone youknowone added the z-ca-2026 Tag to track Contribution Academy 2026 label Aug 1, 2026

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@youknowone
youknowone merged commit c9e48ba into RustPython:main Aug 1, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

z-ca-2026 Tag to track Contribution Academy 2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Align sqlite3 autocommit transaction handling with CPython

3 participants