From ac08f65705c616cf9da66571d825d9a4280c5b3d Mon Sep 17 00:00:00 2001 From: Jiseok CHOI Date: Sun, 27 Jul 2025 17:58:45 +0900 Subject: [PATCH] stdlib(sqlite): Raise ProgrammingError in closed Blob context manager --- Lib/test/test_sqlite3/test_dbapi.py | 2 -- stdlib/src/sqlite.rs | 11 +++++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_sqlite3/test_dbapi.py b/Lib/test/test_sqlite3/test_dbapi.py index bdab745de3..b123786db0 100644 --- a/Lib/test/test_sqlite3/test_dbapi.py +++ b/Lib/test/test_sqlite3/test_dbapi.py @@ -1452,8 +1452,6 @@ class DummyException(Exception): raise DummyException("reraised") - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_blob_closed(self): with memory_database() as cx: cx.execute("create table test(b blob)") diff --git a/stdlib/src/sqlite.rs b/stdlib/src/sqlite.rs index cc146b3786..96c5bbebe3 100644 --- a/stdlib/src/sqlite.rs +++ b/stdlib/src/sqlite.rs @@ -2145,13 +2145,16 @@ mod _sqlite { } #[pymethod] - fn __enter__(zelf: PyRef) -> PyRef { - zelf + fn __enter__(zelf: PyRef, vm: &VirtualMachine) -> PyResult> { + let _ = zelf.inner(vm)?; + Ok(zelf) } #[pymethod] - fn __exit__(&self, _args: FuncArgs) { - self.close() + fn __exit__(&self, _args: FuncArgs, vm: &VirtualMachine) -> PyResult<()> { + let _ = self.inner(vm)?; + self.close(); + Ok(()) } fn inner(&self, vm: &VirtualMachine) -> PyResult> {