-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix sqlite Cursor initialization check #6198
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
Fix sqlite Cursor initialization check #6198
Conversation
WalkthroughCursor lifecycle management in SQLite module was refactored. A new Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant PyNew as py_new
participant Cursor as Cursor
participant Init as __init__
participant Inner as CursorInner
User->>PyNew: create Cursor
PyNew->>Cursor: new_uninitialized(conn, vm)
Cursor-->>User: Cursor (inner=None)
User->>Init: __init__(connection, vm)
rect rgb(220, 240, 255)
Note over Init: Lazy Initialization
Init->>Inner: create with closed=false
Init->>Cursor: set inner, description, rowcount, etc.
end
Init-->>User: initialized
User->>Cursor: execute/fetch operations
rect rgb(255, 240, 220)
Note over Cursor: Closed State Check
alt inner is None
Cursor-->>User: error: "Base Cursor.__init__ not called."
else inner.closed is true
Cursor-->>User: error: "Cannot operate on a closed cursor."
else normal
Cursor-->>User: operation result
end
end
User->>Cursor: close(vm)
rect rgb(240, 255, 240)
Note over Cursor: Cleanup & Mark Closed
Cursor->>Inner: close statement if present
Cursor->>Inner: set closed=true
end
Cursor-->>User: Ok(())
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes The changes introduce a new cursor initialization pattern with state management across multiple interdependent modifications. Review requires understanding the lazy initialization flow, closed-state enforcement logic, and error-handling refinements, with attention to edge cases around uninitialized vs. closed states. Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (2)**/*.rs📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
{vm,stdlib}/**/*.rs📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
🧬 Code graph analysis (1)stdlib/src/sqlite.rs (2)
🔇 Additional comments (7)
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 |
ddc3666 to
1d623e5
Compare
Add proper __init__ validation for sqlite3.Cursor to ensure base class __init__ is called before using cursor methods. This fixes the test_cursor_constructor_call_check test case. Changes: - Modified Cursor to initialize with inner=None in py_new - Added explicit __init__ method that sets up CursorInner - Updated close() method to check for uninitialized state - Changed error message to match CPython: 'Base Cursor.__init__ not called.' This ensures CPython compatibility where attempting to use a Cursor instance without calling the base __init__ raises ProgrammingError.
1d623e5 to
5f7a823
Compare
youknowone
left a 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.
👍
Add proper init validation for sqlite3.Cursor to ensure base class init is called before using cursor methods. This fixes the test_cursor_constructor_call_check test case.
Changes:
Summary by CodeRabbit
Release Notes
New Features
__init__method.Bug Fixes