diff --git a/Lib/test/test_sqlite3/test_factory.py b/Lib/test/test_sqlite3/test_factory.py index d19b98b2056..2816bd91253 100644 --- a/Lib/test/test_sqlite3/test_factory.py +++ b/Lib/test/test_sqlite3/test_factory.py @@ -112,7 +112,6 @@ def test_invalid_factory(self): class RowFactoryTestsBackwardsCompat(MemoryDatabaseMixin, unittest.TestCase): - @unittest.expectedFailure # TODO: RUSTPYTHON def test_is_produced_by_factory(self): cur = self.con.cursor(factory=MyCursor) cur.execute("select 4+5 as foo") diff --git a/crates/stdlib/src/_sqlite3.rs b/crates/stdlib/src/_sqlite3.rs index 1a11d1cbfbd..971c4ec13ac 100644 --- a/crates/stdlib/src/_sqlite3.rs +++ b/crates/stdlib/src/_sqlite3.rs @@ -1043,8 +1043,10 @@ mod _sqlite3 { ))); } - if let Some(cursor_ref) = cursor.downcast_ref::() { - let _ = unsafe { cursor_ref.row_factory.swap(zelf.row_factory.to_owned()) }; + if let Some(cursor_ref) = cursor.downcast_ref::() + && let Some(factory) = zelf.row_factory.to_owned() + { + let _ = unsafe { cursor_ref.row_factory.swap(Some(factory)) }; } Ok(cursor) @@ -1977,6 +1979,16 @@ mod _sqlite3 { Ok(()) } + #[pygetset] + fn row_factory(&self) -> Option { + self.row_factory.to_owned() + } + + #[pygetset(setter)] + fn set_row_factory(&self, val: Option) { + let _ = unsafe { self.row_factory.swap(val) }; + } + fn build_row_cast_map( &self, st: &SqliteStatementRaw,