Ensure sqlite blob methods respect closed connections by ever0de · Pull Request #6290 · RustPython/RustPython
Walkthrough
A new internal method ensure_connection_open() was added to the Blob struct to centralize connection open state validation. All Blob operations (read, write, tell, seek, enter, exit, subscript, and ass_subscript) now invoke this check, ensuring consistent ProgrammingError propagation when operating on closed connections.
Changes
| Cohort / File(s) | Summary |
|---|---|
Blob connection state validation crates/stdlib/src/sqlite.rs |
Added ensure_connection_open() method to Blob; updated read, write, tell, seek, enter, exit, subscript, and ass_subscript methods to invoke this check before proceeding, replacing individual openness checks |
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~12 minutes
- Verify that
ensure_connection_open()is called in all relevant Blob methods - Confirm that no Blob operations bypass the connection state check
- Validate error handling and ProgrammingError propagation behavior
Possibly related PRs
- fix(sqlite): raise
ProgrammingErrorwhen operating on a blob with a… #6286: AddsConnection::is_closed()method and applies the check toBlob::read(), forming the foundation this PR builds upon - Fix sqlite connection reinitialization #6288: Modifies
Connection.initializedand reinitialization behavior, affecting the connection state used by blob operations - stdlib(sqlite): Raise ProgrammingError in closed Blob context manager #6041: Updates
Blob.__enter__()and__exit__()to be VM-aware, overlapping with methods now gated byensure_connection_open()
Suggested reviewers
- youknowone
- ShaharNaveh
Poem
🐰 A blob without a home so bright,
Now checks if doors are locked up tight!
With one small guard to seal the gate,
All operations validate.
No sneaking past a closed connection's might! 🔒
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | Docstring coverage is 63.64% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title clearly and specifically describes the main change: adding closed connection checks to sqlite blob methods, which matches the changeset's core objective. |
| Linked Issues check | ✅ Passed | The changes fully address issue #6289 by introducing a centralized ensure_connection_open() method that all blob operations invoke to check connection state, matching the expected behavior. |
| Out of Scope Changes check | ✅ Passed | All changes are focused on adding connection state validation to blob methods in sqlite.rs, which is directly aligned with the requirements in issue #6289. |
✨ Finishing touches
- 📝 Generate docstrings
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a comment
📜 Recent review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/stdlib/src/sqlite.rs(7 hunks)
⏰ 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). (12)
- GitHub Check: Run tests under miri
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Check the WASM package and demo
- GitHub Check: Check Rust code with clippy
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: auto_format
🔇 Additional comments (2)
crates/stdlib/src/sqlite.rs (2)
2210-2219: LGTM! Well-designed helper method.The
ensure_connection_open()helper method is a clean solution that centralizes the connection state check. The error message clearly distinguishes between a closed database connection and a closed blob, which aids in debugging.
2227-2227: Implementation matches CPython behavior—all Blob methods properly handle closed connections.Verification confirms that all Blob methods (read, write, tell, seek, enter, exit, getitem, setitem) correctly raise ProgrammingError with a clear "closed" message when operating on a blob after the connection has been closed, matching CPython's sqlite3 behavior exactly.
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 @coderabbitai help to get the list of available commands and usage tips.