Skip to content

Commit 81acb9b

Browse files
authored
sqlite3: handle int type in Connection.timeout parameter (#7237)
1 parent 5a1b335 commit 81acb9b

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

Lib/test/test_sqlite3/test_dbapi.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,6 @@ class MultiprocessTests(unittest.TestCase):
19281928
def tearDown(self):
19291929
unlink(TESTFN)
19301930

1931-
@unittest.expectedFailure # TODO: RUSTPYTHON multiprocess test fails
19321931
def test_ctx_mgr_rollback_if_commit_failed(self):
19331932
# bpo-27334: ctx manager does not rollback if commit fails
19341933
SCRIPT = f"""if 1:

Lib/test/test_sqlite3/test_transactions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from .util import MemoryDatabaseMixin
3232

3333

34-
@unittest.skip("TODO: RUSTPYTHON timeout parameter does not accept int type")
3534
class TransactionTests(unittest.TestCase):
3635
def setUp(self):
3736
# We can disable the busy handlers, since we control

crates/stdlib/src/_sqlite3.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ mod _sqlite3 {
6161
},
6262
convert::IntoObject,
6363
function::{
64-
ArgCallable, ArgIterable, FsPath, FuncArgs, OptionalArg, PyComparisonValue,
64+
ArgCallable, ArgIterable, Either, FsPath, FuncArgs, OptionalArg, PyComparisonValue,
6565
PySetterValue,
6666
},
6767
object::{Traverse, TraverseFn},
@@ -333,8 +333,8 @@ mod _sqlite3 {
333333
struct ConnectArgs {
334334
#[pyarg(any)]
335335
database: FsPath,
336-
#[pyarg(any, default = 5.0)]
337-
timeout: f64,
336+
#[pyarg(any, default = Either::A(5.0))]
337+
timeout: Either<f64, i64>,
338338
#[pyarg(any, default = 0)]
339339
detect_types: c_int,
340340
#[pyarg(any, default = Some(vm.ctx.empty_str.to_owned()))]
@@ -991,7 +991,10 @@ mod _sqlite3 {
991991
fn initialize_db(args: &ConnectArgs, vm: &VirtualMachine) -> PyResult<Sqlite> {
992992
let path = args.database.to_cstring(vm)?;
993993
let db = Sqlite::from(SqliteRaw::open(path.as_ptr(), args.uri, vm)?);
994-
let timeout = (args.timeout * 1000.0) as c_int;
994+
let timeout = (match args.timeout {
995+
Either::A(float) => float,
996+
Either::B(int) => int as f64,
997+
} * 1000.0) as c_int;
995998
db.busy_timeout(timeout);
996999
if let Some(isolation_level) = &args.isolation_level {
9971000
begin_statement_ptr_from_isolation_level(isolation_level, vm)?;

0 commit comments

Comments
 (0)