Skip to content

Conversation

@ever0de
Copy link
Contributor

@ever0de ever0de commented Nov 22, 2025

Fixed #6289

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for blob operations when accessing a closed database connection, ensuring consistent error reporting across all blob operations.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 22, 2025

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

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 ⚠️ Warning 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

📥 Commits

Reviewing files that changed from the base of the PR and between a9469a2 and e400782.

📒 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.

❤️ Share

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

Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

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

👍

@youknowone youknowone merged commit f61b62e into RustPython:main Nov 23, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlite: Raise ProgrammingError when operating on a closed connection in Blob methods

2 participants