Skip to content

Commit 567fb4d

Browse files
authored
fix(sqlite): raise ProgrammingError when operating on a blob with a closed connection, (RustPython#6286)
Fixed RustPython#6285
1 parent f7ddcd2 commit 567fb4d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Lib/test/test_sqlite3/test_dbapi.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,8 +1469,6 @@ def test_blob_closed(self):
14691469
with self.assertRaisesRegex(sqlite.ProgrammingError, msg):
14701470
blob[0] = b""
14711471

1472-
# TODO: RUSTPYTHON
1473-
@unittest.expectedFailure
14741472
def test_blob_closed_db_read(self):
14751473
with memory_database() as cx:
14761474
cx.execute("create table test(b blob)")

crates/stdlib/src/sqlite.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,10 @@ mod _sqlite {
10071007
Ok(())
10081008
}
10091009

1010+
fn is_closed(&self) -> bool {
1011+
self.db.lock().is_none()
1012+
}
1013+
10101014
#[pymethod]
10111015
fn commit(&self, vm: &VirtualMachine) -> PyResult<()> {
10121016
self.db_lock(vm)?.implicit_commit(vm)
@@ -2169,6 +2173,13 @@ mod _sqlite {
21692173
length: OptionalArg<c_int>,
21702174
vm: &VirtualMachine,
21712175
) -> PyResult<PyRef<PyBytes>> {
2176+
if self.connection.is_closed() {
2177+
return Err(new_programming_error(
2178+
vm,
2179+
"Cannot operate on a closed database".to_owned(),
2180+
));
2181+
}
2182+
21722183
let mut length = length.unwrap_or(-1);
21732184
let mut inner = self.inner(vm)?;
21742185
let blob_len = inner.blob.bytes();

0 commit comments

Comments
 (0)