Skip to content

Commit efb8b02

Browse files
Fix FilesExt upload fails when content size is zero
1 parent 49eb17b commit efb8b02

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

NEXT_CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### Bug Fixes
88

9+
- Fix `FilesExt.upload` and `FilesExt.upload_from` would fail when the source content is empty and `use_parallel=True`.
10+
911
### Documentation
1012

1113
### Internal Changes

databricks/sdk/mixins/files.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,9 @@ def upload(
11341134
f"Upload context: part_size={ctx.part_size}, batch_size={ctx.batch_size}, content_length={ctx.content_length}"
11351135
)
11361136

1137-
if ctx.use_parallel:
1137+
if ctx.use_parallel and (
1138+
ctx.content_length is None or ctx.content_length >= self._config.files_ext_multipart_upload_min_stream_size
1139+
):
11381140
self._parallel_upload_from_stream(ctx, content)
11391141
return UploadStreamResult()
11401142
elif ctx.content_length is not None:
@@ -1206,7 +1208,7 @@ def upload_from(
12061208
use_parallel=use_parallel,
12071209
parallelism=parallelism,
12081210
)
1209-
if ctx.use_parallel:
1211+
if ctx.use_parallel and ctx.content_length >= self._config.files_ext_multipart_upload_min_stream_size:
12101212
self._parallel_upload_from_file(ctx)
12111213
return UploadFileResult()
12121214
else:

tests/test_files.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,7 @@ def processor() -> list:
16621662
request_json = request.json()
16631663
etags = {}
16641664

1665+
assert len(request_json["parts"]) > 0
16651666
for part in request_json["parts"]:
16661667
etags[part["part_number"]] = part["etag"]
16671668

@@ -1738,10 +1739,17 @@ def to_string(test_case: "MultipartUploadTestCase") -> str:
17381739
[
17391740
# -------------------------- happy cases --------------------------
17401741
MultipartUploadTestCase(
1741-
"Multipart upload successful: single part",
1742+
"Multipart upload successful: single part because of small file",
17421743
content_size=1024 * 1024, # less than part size
1743-
multipart_upload_part_size=10 * 1024 * 1024,
1744+
multipart_upload_min_stream_size=10 * 1024 * 1024,
17441745
expected_part_size=1024 * 1024, # chunk size is used
1746+
expected_single_shot_upload=True,
1747+
),
1748+
MultipartUploadTestCase(
1749+
"Multipart upload successful: empty file",
1750+
content_size=0, # less than part size
1751+
multipart_upload_min_stream_size=100 * 1024 * 1024, # all files smaller than 100M goes to single-shot
1752+
expected_single_shot_upload=True,
17451753
),
17461754
MultipartUploadTestCase(
17471755
"Multipart upload successful: multiple parts (aligned)",

0 commit comments

Comments
 (0)