| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
WalkthroughThe SQLite Connection initialization now centralizes opening logic in initialize_db(). Base Connection instances initialize eagerly in py_new, while subclassed Connection objects start uninitialized and require an explicit __init__ call; error messaging for uninitialized base connections was updated. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant py_new
participant initialize_db
participant SubclassInit as __init__ (subclass)
User->>py_new: Create Connection
alt Base class
py_new->>initialize_db: initialize_db(args, vm)
initialize_db-->>py_new: Sqlite
py_new->>py_new: store PyMutex(Some(db))
py_new-->>User: Ready
else Subclass
py_new->>py_new: store PyMutex(None)
py_new-->>User: Returned (uninitialized)
User->>SubclassInit: __init__(args, vm)
SubclassInit->>initialize_db: initialize_db(args, vm)
initialize_db-->>SubclassInit: Sqlite
SubclassInit->>SubclassInit: set PyMutex(Some(db))
SubclassInit-->>User: Ready
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
📜 Recent review details Configuration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro 📥 CommitsReviewing files that changed from the base of the PR and between 38e9fc5 and df09182. 📒 Files selected for processing (1)
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. ❤️ ShareComment @coderabbitai help to get the list of available commands and usage tips. |
Sorry, something went wrong.
Add proper __init__ validation for sqlite3.Connection to ensure base class __init__ is called before using connection methods. This fixes the test_connection_constructor_call_check test case. Changes: - Modified Connection.py_new to detect subclassing - For base Connection class, initialization happens immediately in py_new - For subclassed Connection, db is initialized as None - Added __init__ method that performs actual database initialization - Updated _db_lock error message to match CPython: 'Base Connection.__init__ not called.' This ensures CPython compatibility where attempting to use a Connection subclass instance without calling the base __init__ raises ProgrammingError.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)stdlib/src/sqlite.rs (2)📜 Review details900-910: Clamp timeout to avoid c_int overflow
let timeout = (args.timeout * 1000.0) as c_int; can overflow for large timeouts. Clamp and round before casting.
Apply within this block:
- let timeout = (args.timeout * 1000.0) as c_int; - db.busy_timeout(timeout); + // Saturate to c_int::MAX and avoid negatives + let timeout_ms = (args.timeout * 1000.0).clamp(0.0, i32::MAX as f64).round() as c_int; + db.busy_timeout(timeout_ms);
911-922: Subclass init path: good; consider making sqlite.connect() call the factory so init runs
__init__ correctly performs one-time DB open for subclassed instances. However, sqlite.connect() still constructs via Connection::py_new(...), so a factory=SubClass won’t execute the subclass’ __init__ (unlike CPython, which calls factory(...)). Recommend updating connect() to invoke the factory type, letting Python dispatch call __new__ then __init__.
Proposed approach (conceptual; outside this hunk): build args tuple matching ConnectArgs order and call the type:
// Pseudocode: call the chosen factory so __init__ runs for subclasses // let obj = vm.invoke(args.factory.clone().into_object(), // (args.database, args.timeout, args.detect_types, args.isolation_level, // args.check_same_thread, /* omit passing 'factory' itself */ // args.cached_statements, args.uri))?;Please verify no downstream assumptions rely on the current “py_new-only” construction.
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📥 CommitsReviewing files that changed from the base of the PR and between fcf1969 and 38e9fc5.
⛔ Files ignored due to path filters (1)📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Format Rust code with the default rustfmt style (run cargo fmt)
Run clippy and fix any warnings or lints introduced by your changes
Follow Rust best practices for error handling and memory management
Files:
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use RustPython macros (pyclass, pymodule, pyfunction, etc.) when implementing Python functionality in Rust
Files:
vm/src/builtins/type.rs (1)⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)vm/src/object/core.rs (1)
- class (147-149)
Lib/test/test_sqlite3/test_regression.py (1)
- class (671-673)
- Connection (229-231)
stdlib/src/sqlite.rs (2)854-879: Eager base init + deferred subclass init is correct
Type check via cls.is(Connection::class(&vm.ctx).as_object()) and gating db initialization achieves the CPython-compatible behavior while preserving defaults (text_factory, thread id). Looks good.
936-940: Error text parity with CPython
Updated message “Base Connection.init not called.” matches expected test string and CPython behavior. Good.
Run the sqlite3 regression test to confirm: test_connection_constructor_call_check passes with this change.
Sorry, something went wrong.
| #[pymethod] | ||
| fn __init__(&self, args: ConnectArgs, vm: &VirtualMachine) -> PyResult<()> { |
There was a problem hiding this comment.
We also have an Initializer trait. It’s like the Constructor trait.
Would you apply this trait as well?
Sorry, something went wrong.
There was a problem hiding this comment.
Oh, I'd forgotten because it's been a while. Thank you
Sorry, something went wrong.
There was a problem hiding this comment.
Great, thank you!
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Add proper init validation for sqlite3.Connection to ensure base class init is called before using connection methods. This fixes the test_connection_constructor_call_check test case.
Changes:
Summary by CodeRabbit
Bug Fixes
Improvements