Skip to content

Commit 681b2d4

Browse files
Revert interface change of FilesExt.upload (#1092)
## What changes are proposed in this pull request? Provide the readers and reviewers with the information they need to understand this PR in a comprehensive manner. Specifically, try to answer the two following questions: - **WHAT** - Fix the issue where `FilesExt.upload`'s second parameter was changed from `contents` to `content` unintentionally. This PR reverts the change to make it compatible with the interface prior than version 0.68.0. - **WHY** - 0.69.0 introduced a breaking change unintentionally, which breaks the usage for certain users. e.g. #1091 ## How is this tested? The unit tests has been updated to check the parameter name.
1 parent 49eb17b commit 681b2d4

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
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 the issue where `FilesExt.upload`'s second parameter was changed from `contents` to `content` unintentionally. Now the interface is backward compatible to versions previous than 0.69.0.
10+
911
### Documentation
1012

1113
### Internal Changes

databricks/sdk/mixins/files.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ def _get_optimized_performance_parameters_for_upload(
10641064
def upload(
10651065
self,
10661066
file_path: str,
1067-
content: BinaryIO,
1067+
contents: BinaryIO,
10681068
*,
10691069
overwrite: Optional[bool] = None,
10701070
part_size: Optional[int] = None,
@@ -1076,7 +1076,7 @@ def upload(
10761076
10771077
:param file_path: str
10781078
The absolute remote path of the target file, e.g. /Volumes/path/to/your/file
1079-
:param content: BinaryIO
1079+
:param contents: BinaryIO
10801080
The contents of the file to upload. This must be a BinaryIO stream.
10811081
:param overwrite: bool (optional)
10821082
If true, an existing file will be overwritten. When not specified, assumed True.
@@ -1096,7 +1096,7 @@ def upload(
10961096

10971097
if self._config.disable_experimental_files_api_client:
10981098
_LOG.info("Disable experimental files API client, will use the original upload method.")
1099-
super().upload(file_path=file_path, contents=content, overwrite=overwrite)
1099+
super().upload(file_path=file_path, contents=contents, overwrite=overwrite)
11001100
return UploadStreamResult()
11011101

11021102
_LOG.debug(f"Uploading file from BinaryIO stream")
@@ -1107,12 +1107,12 @@ def upload(
11071107

11081108
# Determine content length if the stream is seekable
11091109
content_length = None
1110-
if content.seekable():
1110+
if contents.seekable():
11111111
_LOG.debug(f"Uploading using seekable mode")
11121112
# If the stream is seekable, we can read its size.
1113-
content.seek(0, os.SEEK_END)
1114-
content_length = content.tell()
1115-
content.seek(0)
1113+
contents.seek(0, os.SEEK_END)
1114+
content_length = contents.tell()
1115+
contents.seek(0)
11161116

11171117
# Get optimized part size and batch size based on content length and provided part size
11181118
optimized_part_size, optimized_batch_size = self._get_optimized_performance_parameters_for_upload(
@@ -1135,17 +1135,17 @@ def upload(
11351135
)
11361136

11371137
if ctx.use_parallel:
1138-
self._parallel_upload_from_stream(ctx, content)
1138+
self._parallel_upload_from_stream(ctx, contents)
11391139
return UploadStreamResult()
11401140
elif ctx.content_length is not None:
1141-
self._upload_single_thread_with_known_size(ctx, content)
1141+
self._upload_single_thread_with_known_size(ctx, contents)
11421142
return UploadStreamResult()
11431143
else:
11441144
_LOG.debug(f"Uploading using non-seekable mode")
11451145
# If the stream is not seekable, we cannot determine its size.
11461146
# We will use a multipart upload.
11471147
_LOG.debug(f"Using multipart upload for non-seekable input stream of unknown size for file {file_path}")
1148-
self._single_thread_multipart_upload(ctx, content)
1148+
self._single_thread_multipart_upload(ctx, contents)
11491149
return UploadStreamResult()
11501150

11511151
def upload_from(

tests/test_files.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ def run(self, config: Config, monkeypatch) -> None:
10851085
custom_response_download_from_url=CustomResponse(
10861086
code=403,
10871087
first_invocation=2,
1088-
last_invocation=4,
1088+
last_invocation=3,
10891089
body=PresignedUrlDownloadTestCase.expired_url_aws_response,
10901090
),
10911091
),
@@ -1375,17 +1375,17 @@ def processor() -> list:
13751375
def upload() -> None:
13761376
if source_type == UploadSourceType.FILE:
13771377
w.files.upload_from(
1378-
self.path,
1379-
content_or_source,
1378+
file_path=self.path,
1379+
source_path=content_or_source,
13801380
overwrite=self.overwrite,
13811381
part_size=self.multipart_upload_part_size,
13821382
use_parallel=use_parallel,
13831383
parallelism=self.parallelism,
13841384
)
13851385
else:
13861386
w.files.upload(
1387-
self.path,
1388-
content_or_source,
1387+
file_path=self.path,
1388+
contents=content_or_source,
13891389
overwrite=self.overwrite,
13901390
part_size=self.multipart_upload_part_size,
13911391
use_parallel=use_parallel,

0 commit comments

Comments
 (0)