-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(sqlite): raise ProgrammingError when operating on a blob with a…
#6286
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1007,6 +1007,10 @@ mod _sqlite { | |
| Ok(()) | ||
| } | ||
|
|
||
| fn is_closed(&self) -> bool { | ||
| self.db.lock().is_none() | ||
| } | ||
|
|
||
| #[pymethod] | ||
| fn commit(&self, vm: &VirtualMachine) -> PyResult<()> { | ||
| self.db_lock(vm)?.implicit_commit(vm) | ||
|
|
@@ -2169,6 +2173,13 @@ mod _sqlite { | |
| length: OptionalArg<c_int>, | ||
| vm: &VirtualMachine, | ||
| ) -> PyResult<PyRef<PyBytes>> { | ||
| if self.connection.is_closed() { | ||
| return Err(new_programming_error( | ||
| vm, | ||
| "Cannot operate on a closed database".to_owned(), | ||
| )); | ||
| } | ||
|
Comment on lines
+2176
to
+2181
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify that other blob methods handle closed connections correctly. The check for closed connections in Run the following script to examine if other blob methods should also include the closed-connection check: 🏁 Script executed: #!/bin/bash
# Description: Search for all Blob methods to verify consistent closed-connection handling
echo "=== Blob methods in the file ==="
ast-grep --pattern $'impl Blob {
$$$
fn $METHOD($$$) $$$
$$$
}'
echo -e "\n=== Checking which methods call connection.db_lock or check connection state ==="
rg -n -A5 -B2 'impl Blob' crates/stdlib/src/sqlite.rs | rg -A5 'fn (write|tell|seek|__enter__|__exit__|subscript|ass_subscript)'Length of output: 114 The web search doesn't provide targeted information about the specific codebase. Let me generate new shell scripts to examine the Blob implementation directly: 🏁 Script executed: #!/bin/bash
# Description: Extract Blob impl block and examine all methods
echo "=== Finding impl Blob block ==="
rg -n 'impl Blob' crates/stdlib/src/sqlite.rs -A 300
echo -e "\n=== Counting methods in Blob impl ==="
rg -n 'fn ' crates/stdlib/src/sqlite.rs | grep -A1 -B1 'Blob'Length of output: 12999 🏁 Script executed: #!/bin/bash
# Search for CPython's blob.c file content from GitHub
echo "=== Searching for CPython blob.c on GitHub ==="
curl -s https://raw.githubusercontent.com/python/cpython/main/Modules/_sqlite/blob.c | head -400Length of output: 9655 Add closed-connection check to other blob methods for consistency with CPython behavior. CPython's
Without these checks, operations on other methods could fail with unclear errors when the connection is closed, unlike CPython which provides a consistent error message. 🤖 Prompt for AI Agents
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ever0de How do you think about this comment?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @youknowone Can I handle this in a separate issue? |
||
|
|
||
| let mut length = length.unwrap_or(-1); | ||
| let mut inner = self.inner(vm)?; | ||
| let blob_len = inner.blob.bytes(); | ||
|
|
||
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.
Can you please put the link in the PR here? it will be easier to access rather than going to git blame -> PR -> links
Uh oh!
There was an error while loading. Please reload this page.
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.
Could you please clarify the context? I am currently unable to understand why it's required.
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.
Not required. Just my personal preference
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.
This isn’t the official stance of our project, but I’d like to share my personal view on the matter.
If the behavior is something that’s common sense and easily predictable, I don’t think we need to attach a reference. In my opinion, this change falls into that category. Before adding this code, it might have been unclear whether such a check was necessary, but once the code is added, it becomes obvious that it is.
Some behaviors are hard to infer from the code alone. In those cases, having a reference linked is helpful. Depending on the situation, when pointing to the exact code is useful, we link specific line numbers; when it’s more important to refer to the conceptual location, we just mention the function name instead.