Skip to content

Commit d8f1d18

Browse files
authored
stdlib(sqlite): Raise ProgrammingError in closed Blob context manager (#6041)
1 parent 89c58d6 commit d8f1d18

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Lib/test/test_sqlite3/test_dbapi.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,8 +1452,6 @@ class DummyException(Exception):
14521452
raise DummyException("reraised")
14531453

14541454

1455-
# TODO: RUSTPYTHON
1456-
@unittest.expectedFailure
14571455
def test_blob_closed(self):
14581456
with memory_database() as cx:
14591457
cx.execute("create table test(b blob)")

stdlib/src/sqlite.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,13 +2145,16 @@ mod _sqlite {
21452145
}
21462146

21472147
#[pymethod]
2148-
fn __enter__(zelf: PyRef<Self>) -> PyRef<Self> {
2149-
zelf
2148+
fn __enter__(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
2149+
let _ = zelf.inner(vm)?;
2150+
Ok(zelf)
21502151
}
21512152

21522153
#[pymethod]
2153-
fn __exit__(&self, _args: FuncArgs) {
2154-
self.close()
2154+
fn __exit__(&self, _args: FuncArgs, vm: &VirtualMachine) -> PyResult<()> {
2155+
let _ = self.inner(vm)?;
2156+
self.close();
2157+
Ok(())
21552158
}
21562159

21572160
fn inner(&self, vm: &VirtualMachine) -> PyResult<PyMappedMutexGuard<'_, BlobInner>> {

0 commit comments

Comments
 (0)