sqlite: Throw TypeError when callable is not callable (#4923)

This commit is contained in:
Lee Dogeon
2023-04-22 07:10:44 +09:00
committed by GitHub
parent f0db8329be
commit 1fa69ebcc9
2 changed files with 5 additions and 3 deletions

View File

@@ -36,8 +36,6 @@ class CollationTests(unittest.TestCase):
with self.assertRaises(TypeError):
con.create_collation(None, lambda x, y: (x > y) - (x < y))
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_create_collation_not_callable(self):
con = sqlite.connect(":memory:")
with self.assertRaises(TypeError) as cm:

View File

@@ -1107,7 +1107,7 @@ mod _sqlite {
) -> PyResult<()> {
let name = name.to_cstring(vm)?;
let db = self.db_lock(vm)?;
let Some(data )= CallbackData::new(callable, vm) else {
let Some(data) = CallbackData::new(callable.clone(), vm) else {
unsafe {
sqlite3_create_collation_v2(db.db, name.as_ptr(), SQLITE_UTF8, null_mut(), None, None);
}
@@ -1115,6 +1115,10 @@ mod _sqlite {
};
let data = Box::into_raw(Box::new(data));
if !callable.is_callable() {
return Err(vm.new_type_error("parameter must be callable".to_owned()));
}
let ret = unsafe {
sqlite3_create_collation_v2(
db.db,