Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Lib/test/test_sqlite3/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1930,7 +1930,6 @@ class MultiprocessTests(unittest.TestCase):
def tearDown(self):
unlink(TESTFN)

@unittest.expectedFailure # TODO: RUSTPYTHON multiprocess test fails
def test_ctx_mgr_rollback_if_commit_failed(self):
# bpo-27334: ctx manager does not rollback if commit fails
SCRIPT = f"""if 1:
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_sqlite3/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from .util import MemoryDatabaseMixin


@unittest.skip("TODO: RUSTPYTHON timeout parameter does not accept int type")
class TransactionTests(unittest.TestCase):
def setUp(self):
# We can disable the busy handlers, since we control
Expand Down
11 changes: 7 additions & 4 deletions crates/stdlib/src/_sqlite3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ mod _sqlite3 {
},
convert::IntoObject,
function::{
ArgCallable, ArgIterable, FsPath, FuncArgs, OptionalArg, PyComparisonValue,
ArgCallable, ArgIterable, Either, FsPath, FuncArgs, OptionalArg, PyComparisonValue,
PySetterValue,
},
object::{Traverse, TraverseFn},
Expand Down Expand Up @@ -333,8 +333,8 @@ mod _sqlite3 {
struct ConnectArgs {
#[pyarg(any)]
database: FsPath,
#[pyarg(any, default = 5.0)]
timeout: f64,
#[pyarg(any, default = Either::A(5.0))]
timeout: Either<f64, i64>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing timeout as Either<f64, i64> is a common pattern in Python. If you are interested in, investigating if introducing TimeoutSeconds utility type will be useful or not. (I am not sure yet)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think it's a great idea. Do you think it would be better to separate it into a new PR instead of working on it here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, in separate PR. it is unrelated refactoring

#[pyarg(any, default = 0)]
detect_types: c_int,
#[pyarg(any, default = Some(vm.ctx.empty_str.to_owned()))]
Expand Down Expand Up @@ -991,7 +991,10 @@ mod _sqlite3 {
fn initialize_db(args: &ConnectArgs, vm: &VirtualMachine) -> PyResult<Sqlite> {
let path = args.database.to_cstring(vm)?;
let db = Sqlite::from(SqliteRaw::open(path.as_ptr(), args.uri, vm)?);
let timeout = (args.timeout * 1000.0) as c_int;
let timeout = (match args.timeout {
Either::A(float) => float,
Either::B(int) => int as f64,
} * 1000.0) as c_int;
db.busy_timeout(timeout);
if let Some(isolation_level) = &args.isolation_level {
begin_statement_ptr_from_isolation_level(isolation_level, vm)?;
Expand Down
Loading