Skip to content

Commit 8c97a49

Browse files
committed
Followups
1 parent a146db2 commit 8c97a49

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

databricks/sdk/mixins/files.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
from urllib import parse
2222

2323
import requests
24+
import requests.adapters
2425
from requests import RequestException
2526

2627
from .._base_client import _BaseClient, _RawResponse, _StreamingResponse
2728
from .._property import _cached_property
2829
from ..clock import Clock, RealClock
30+
from ..config import Config
2931
from ..errors import AlreadyExists, NotFound
3032
from ..errors.mapper import _error_mapper
3133
from ..retries import retried
@@ -723,15 +725,14 @@ def download(self, file_path: str) -> DownloadResponse:
723725
initial_response.contents._response = wrapped_response
724726
return initial_response
725727

726-
727728
def upload(self, file_path: str, contents: BinaryIO, *, overwrite: Optional[bool] = None):
728729
# Upload empty and small files with one-shot upload.
729730
pre_read_buffer = contents.read(self._config.multipart_upload_min_stream_size)
730731
if len(pre_read_buffer) < self._config.multipart_upload_min_stream_size:
731732
_LOG.debug(
732733
f"Using one-shot upload for input stream of size {len(pre_read_buffer)} below {self._config.multipart_upload_min_stream_size} bytes"
733734
)
734-
return super().upload(file_path=file_path, contents=pre_read_buffer, overwrite=overwrite)
735+
return super().upload(file_path=file_path, contents=BytesIO(pre_read_buffer), overwrite=overwrite)
735736

736737
query = {"action": "initiate-upload"}
737738
if overwrite is not None:
@@ -829,6 +830,7 @@ def fill_buffer():
829830

830831
headers = {"Content-Type": "application/json"}
831832

833+
# Requesting URLs for the same set of parts is an idempotent operation, safe to retry.
832834
# _api.do() does retry
833835
upload_part_urls_response = self._api.do(
834836
"POST", "/api/2.0/fs/create-upload-part-urls", headers=headers, body=body
@@ -931,6 +933,7 @@ def perform():
931933

932934
body["parts"] = parts
933935

936+
# Completing upload is an idempotent operation, safe to retry.
934937
# _api.do() does retry
935938
self._api.do(
936939
"POST",
@@ -1109,7 +1112,7 @@ def _resumable_upload(
11091112
break
11101113

11111114
elif upload_response.status_code == 308:
1112-
# chunk accepted, let's determine received offset to resume from there
1115+
# chunk accepted (or check-status succeeded), let's determine received offset to resume from there
11131116
range_string = upload_response.headers.get("Range")
11141117
confirmed_offset = self._extract_range_offset(range_string)
11151118
_LOG.debug(f"Received confirmed offset: {confirmed_offset}")

0 commit comments

Comments
 (0)