Skip to content

Commit d797f99

Browse files
authored
sqlite3: allow Row construction with cursor having no description (#8364)
Row(cursor, data) raised ValueError when cursor.description was None. CPython allows this case and returns an empty key list. - Use empty tuple when description is None instead of raising - Include the key name in the IndexError when a string key is not found Assisted-by: GitHub Copilot:claude-sonnet-4-6
1 parent 63542a6 commit d797f99

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

Lib/test/test_sqlite3/test_dbapi.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2045,7 +2045,6 @@ def test_row_equality(self):
20452045

20462046
self.assertNotEqual(r1, r3)
20472047

2048-
@unittest.expectedFailure # TODO: RUSTPYTHON; Row with no description fails
20492048
def test_row_no_description(self):
20502049
cu = self.cx.cursor()
20512050
self.assertIsNone(cu.description)

crates/stdlib/src/_sqlite3.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,7 +2255,7 @@ mod _sqlite3 {
22552255
return self.data.getitem_by_index(vm, i);
22562256
}
22572257
}
2258-
Err(vm.new_index_error("No item with that key"))
2258+
Err(vm.new_index_error(format!("No item with key '{}'", name.to_string_lossy())))
22592259
} else if let Some(slice) = needle.downcast_ref::<PySlice>() {
22602260
let list = self.data.getitem_by_slice(vm, slice.to_saturated(vm)?)?;
22612261
Ok(vm.ctx.new_tuple(list).into())
@@ -2277,7 +2277,7 @@ mod _sqlite3 {
22772277
.inner(vm)?
22782278
.description
22792279
.clone()
2280-
.ok_or_else(|| vm.new_value_error("no description in Cursor"))?;
2280+
.unwrap_or_else(|| vm.ctx.empty_tuple.clone());
22812281

22822282
Ok(Self { data, description })
22832283
}

0 commit comments

Comments
 (0)