This is an automated email from the ASF dual-hosted git repository. Xuanwo pushed a commit to branch xuanwo/python-sync-file-zero-chunk-and-verify in repository https://gitbox.apache.org/repos/asf/opendal.git
commit 6eea5a8dd67baa722ef8a2e0bab69f1685338c8b Author: Xuanwo <[email protected]> AuthorDate: Sun Nov 22 08:58:33 2026 +0100 fix(bindings/python): coalesce synchronous File writes with chunk zero --- bindings/python/src/operator.rs | 4 ++-- bindings/python/tests/test_file_http_requests.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bindings/python/src/operator.rs b/bindings/python/src/operator.rs index 68f180352f..ad7ab0214b 100644 --- a/bindings/python/src/operator.rs +++ b/bindings/python/src/operator.rs @@ -424,8 +424,8 @@ impl Operator { } else if mode == "wb" { let mut writer_opts = writer_opts; // Keep small writes coalesced without the std::io adapter when - // neither the caller nor the service supplies a chunk size. - if writer_opts.chunk.is_none() + // neither the caller nor the service supplies a nonzero chunk size. + if matches!(writer_opts.chunk, None | Some(0)) && this.info().capability().write_multi_min_size.is_none() { writer_opts.chunk = Some(256 * 1024); diff --git a/bindings/python/tests/test_file_http_requests.py b/bindings/python/tests/test_file_http_requests.py index 25ce472616..888019d14e 100644 --- a/bindings/python/tests/test_file_http_requests.py +++ b/bindings/python/tests/test_file_http_requests.py @@ -265,11 +265,13 @@ def test_sync_file_sequential_read_uses_one_request(request_server): file.read(1) -def test_sync_file_flush_keeps_small_writes_coalesced(request_server): [email protected]("chunk", [None, 0], ids=["default", "zero"]) +def test_sync_file_flush_keeps_small_writes_coalesced(request_server, chunk): endpoint, state = request_server state._reset() op = opendal.Operator("webdav", endpoint=endpoint, disable_create_dir="true") - with op.open("file", "wb") as file: + options = {} if chunk is None else {"chunk": chunk} + with op.open("file", "wb", **options) as file: for _ in range(1000): assert file.write(b"small") == 5 file.flush()
