Skip to content

Commit 1fa69eb

Browse files
authored
sqlite: Throw TypeError when callable is not callable (RustPython#4923)
1 parent f0db832 commit 1fa69eb

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Lib/test/test_sqlite3/test_hooks.py

-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ def test_create_collation_not_string(self):
3636
with self.assertRaises(TypeError):
3737
con.create_collation(None, lambda x, y: (x > y) - (x < y))
3838

39-
# TODO: RUSTPYTHON
40-
@unittest.expectedFailure
4139
def test_create_collation_not_callable(self):
4240
con = sqlite.connect(":memory:")
4341
with self.assertRaises(TypeError) as cm:

stdlib/src/sqlite.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1107,14 +1107,18 @@ mod _sqlite {
11071107
) -> PyResult<()> {
11081108
let name = name.to_cstring(vm)?;
11091109
let db = self.db_lock(vm)?;
1110-
let Some(data )= CallbackData::new(callable, vm) else {
1110+
let Some(data) = CallbackData::new(callable.clone(), vm) else {
11111111
unsafe {
11121112
sqlite3_create_collation_v2(db.db, name.as_ptr(), SQLITE_UTF8, null_mut(), None, None);
11131113
}
11141114
return Ok(());
11151115
};
11161116
let data = Box::into_raw(Box::new(data));
11171117

1118+
if !callable.is_callable() {
1119+
return Err(vm.new_type_error("parameter must be callable".to_owned()));
1120+
}
1121+
11181122
let ret = unsafe {
11191123
sqlite3_create_collation_v2(
11201124
db.db,

0 commit comments

Comments
 (0)