-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Upgrade dbm, implement sqlite3 autocommit #6616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Warning Rate limit exceeded@youknowone has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 19 minutes and 59 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughIntroduces autocommit mode mechanism for sqlite3 connections with three modes (Legacy, Enabled, Disabled), adds public Python-facing autocommit property on Connection and Cursor, exposes LEGACY_TRANSACTION_CONTROL constant, adjusts transaction control flow to respect autocommit state, and improves cleanup safety using sqlite3_close_v2 with early-exit validation for closed connections. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client (Python)
participant Conn as Connection
participant Cursor as Cursor
participant SQLite as SQLite DB
alt Autocommit Disabled (Manual)
Client->>Conn: execute(sql)
Conn->>Conn: autocommit check
Conn->>SQLite: BEGIN
Conn->>Cursor: create cursor
Cursor->>SQLite: execute statement
Client->>Conn: commit()
Conn->>SQLite: COMMIT
else Autocommit Enabled
Client->>Conn: execute(sql)
Conn->>Conn: autocommit check
Note over Conn: skip BEGIN
Conn->>Cursor: create cursor
Cursor->>SQLite: execute statement
Note over SQLite: autocommit on DB
else Autocommit Legacy
Client->>Conn: execute(sql)
Conn->>Conn: check LEGACY_TRANSACTION_CONTROL
Conn->>SQLite: BEGIN
Conn->>Cursor: create cursor
Cursor->>SQLite: execute statement
end
Conn->>Conn: close()
Conn->>SQLite: sqlite3_close_v2()
Note over Conn: handles active statements safely
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (8)
Lib/dbm/__init__.pyis excluded by!Lib/**Lib/dbm/dumb.pyis excluded by!Lib/**Lib/dbm/gnu.pyis excluded by!Lib/**Lib/dbm/ndbm.pyis excluded by!Lib/**Lib/dbm/sqlite3.pyis excluded by!Lib/**Lib/test/test_dbm.pyis excluded by!Lib/**Lib/test/test_dbm_dumb.pyis excluded by!Lib/**Lib/test/test_dbm_sqlite3.pyis excluded by!Lib/**
📒 Files selected for processing (1)
crates/stdlib/src/sqlite.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by runningcargo fmtto format Rust code
Always run clippy to lint code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass,pymodule,pyfunction, etc.) when implementing Python functionality in Rust
Files:
crates/stdlib/src/sqlite.rs
🔇 Additional comments (9)
crates/stdlib/src/sqlite.rs (9)
305-338: LGTM!The
AutocommitModeenum and itsTryFromBorrowedObjectimplementation are well-designed. The identity checks (obj.is(&vm.ctx.true_value)) correctly distinguish betweenTrue/Falseand integer values, matching CPython's behavior whereautocommit=1is treated differently fromautocommit=True.
360-361: LGTM!The
autocommitfield correctly uses the derivedDefaultimplementation, which initializes toAutocommitMode::Legacy.
883-883: LGTM!The
autocommitfield usesPyMutex<AutocommitMode>for thread-safe access, consistent with other mutable state in theConnectionstruct.
963-970: LGTM!The autocommit mode is correctly extracted from
ConnectArgsand assigned to the connection during reinitialization.
1778-1791: Consistent withexecute()implementation.The autocommit check mirrors the
execute()method. The same verification regardingAutocommitMode::Disabledbehavior applies here.
2018-2030: Good safety improvement for cleanup on closed connections.This early check ensures that when iterating a cursor after the connection is closed, the statement is properly reset to release file locks. The error message is clear and matches CPython's behavior.
Note: There's a theoretical TOCTOU gap between
is_closed()and the lock acquisition, but this is acceptable since:
- Connection closure is typically single-threaded from Python's perspective
- The later
db_lock(vm)call would catch any race condition- This is primarily a best-effort cleanup improvement
1569-1579: AI summary inconsistency: Cursor does not have autocommit property.The AI-generated summary mentions "Added public methods: autocommit (getter) on class Cursor" and "autocommit: PyMutex" in Cursor, but the actual code correctly implements autocommit only at the Connection level. This is the expected behavior since autocommit is a connection-level setting in Python's sqlite3 module.
364-368: LGTM!The
Traverseimplementation forConnectArgscorrectly excludesautocommitsinceAutocommitModeis a simpleCopyenum with no Python object references that need GC traversal.
1683-1696: No changes required—the transaction logic correctly implements CPython behavior.The code correctly handles
AutocommitMode::Disabled(corresponding toautocommit=False). Per PEP-249 and CPython sqlite3 specifications, whenautocommit=False, implicit transactions viaBEGINare required before DML statements, and the user must explicitly callcommit()orrollback(). The term "manual commit mode" refers to requiring explicit commits after the implicit transaction begins, not the absence of implicit transactions.The condition
*zelf.connection.autocommit.lock() != AutocommitMode::Enabledcorrectly:
- Calls
begin_transaction()forDisabledmode (autocommit=False) → implicit transactions as required ✓- Calls
begin_transaction()forLegacymode → respects isolation_level ✓- Skips
begin_transaction()forEnabledmode (autocommit=True) → true SQLite autocommit ✓
for #6483
cc @ever0de
Summary by CodeRabbit
New Features
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.