diff --git a/Lib/test/test_sqlite3/test_dbapi.py b/Lib/test/test_sqlite3/test_dbapi.py index a60f83f51ad..8962fe00ed8 100644 --- a/Lib/test/test_sqlite3/test_dbapi.py +++ b/Lib/test/test_sqlite3/test_dbapi.py @@ -1096,7 +1096,6 @@ def test_invalid_array_size(self): self.assertRaises(ValueError, setter, -3) self.assertRaises(OverflowError, setter, UINT32_MAX + 1) - @unittest.expectedFailure # TODO: RUSTPYTHON fetchmany behavior with exhausted cursor differs def test_fetchmany(self): # no active SQL statement res = self.cu.fetchmany() diff --git a/crates/stdlib/src/_sqlite3.rs b/crates/stdlib/src/_sqlite3.rs index 971c4ec13ac..8f14f614229 100644 --- a/crates/stdlib/src/_sqlite3.rs +++ b/crates/stdlib/src/_sqlite3.rs @@ -1900,10 +1900,14 @@ mod _sqlite3 { }; let mut list = vec![]; - while let PyIterReturn::Return(row) = Cursor::next(zelf, vm)? { - list.push(row); - if max_rows > 0 && list.len() as c_int >= max_rows { - break; + let mut remaining = max_rows; + while remaining > 0 { + match Cursor::next(zelf, vm)? { + PyIterReturn::Return(row) => { + list.push(row); + remaining -= 1; + } + PyIterReturn::StopIteration(_) => break, } } Ok(list)