Skip to content

Commit 7986398

Browse files
authored
Fix test_files_api_read_twice_from_one_download (#326)
## Changes This integration test is failing (and likely wasn't passing when I merged the original PR). This PR fixes it by unifying the codepaths for `__enter__` and `read` to call `_open`, which consistently will check if the response is closed and throw an exception if so. ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [ ] `make test` run locally - [ ] `make fmt` applied - [ ] relevant integration tests applied
1 parent 99c479e commit 7986398

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

databricks/sdk/core.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,14 @@ def __init__(self, response: requests.Response, chunk_size: Union[int, None] = N
11471147
self._content = None
11481148
self._chunk_size = chunk_size
11491149

1150+
def _open(self) -> None:
1151+
if self._closed:
1152+
raise ValueError("I/O operation on closed file")
1153+
if not self._content:
1154+
self._content = self._response.iter_content(chunk_size=self._chunk_size)
1155+
11501156
def __enter__(self) -> BinaryIO:
1151-
self._content = self._response.iter_content(chunk_size=self._chunk_size)
1157+
self._open()
11521158
return self
11531159

11541160
def set_chunk_size(self, chunk_size: Union[int, None]) -> None:
@@ -1162,10 +1168,7 @@ def isatty(self) -> bool:
11621168
return False
11631169

11641170
def read(self, n: int = -1) -> bytes:
1165-
if self._closed is None:
1166-
raise ValueError("I/O operation on closed file")
1167-
if not self._content:
1168-
self._content = self._response.iter_content(chunk_size=self._chunk_size)
1171+
self._open()
11691172
read_everything = n < 0
11701173
remaining_bytes = n
11711174
res = b''

0 commit comments

Comments
 (0)