Skip to content

Commit 051716c

Browse files
fix: Support status codes with no content (box/box-codegen#604) (#378)
1 parent d78f9c6 commit 051716c

File tree

15 files changed

+108
-30
lines changed

15 files changed

+108
-30
lines changed

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "c4810bd", "specHash": "c2c76f3", "version": "1.7.0" }
1+
{ "engineHash": "37e1577", "specHash": "c2c76f3", "version": "1.7.0" }

box_sdk_gen/managers/chunked_uploads.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ def create_file_upload_session_commit_by_url(
624624
if_match: Optional[str] = None,
625625
if_none_match: Optional[str] = None,
626626
extra_headers: Optional[Dict[str, Optional[str]]] = None
627-
) -> Files:
627+
) -> Optional[Files]:
628628
"""
629629
Using this method with urls provided in response when creating a new upload session is preferred to use over CreateFileUploadSessionCommit method.
630630
@@ -692,7 +692,9 @@ def create_file_upload_session_commit_by_url(
692692
network_session=self.network_session,
693693
)
694694
)
695-
return deserialize(response.data, Files)
695+
if to_string(response.status) == '202':
696+
return None
697+
return deserialize(response.data, Optional[Files])
696698

697699
def create_file_upload_session_commit(
698700
self,
@@ -703,7 +705,7 @@ def create_file_upload_session_commit(
703705
if_match: Optional[str] = None,
704706
if_none_match: Optional[str] = None,
705707
extra_headers: Optional[Dict[str, Optional[str]]] = None
706-
) -> Files:
708+
) -> Optional[Files]:
707709
"""
708710
Close an upload session and create a file from the uploaded chunks.
709711
@@ -773,7 +775,9 @@ def create_file_upload_session_commit(
773775
network_session=self.network_session,
774776
)
775777
)
776-
return deserialize(response.data, Files)
778+
if to_string(response.status) == '202':
779+
return None
780+
return deserialize(response.data, Optional[Files])
777781

778782
def _reducer(self, acc: _PartAccumulator, chunk: ByteStream) -> _PartAccumulator:
779783
last_index: int = acc.last_index
@@ -860,7 +864,7 @@ def upload_big_file(
860864
assert processed_session_parts.total_count == total_parts
861865
sha_1: str = file_hash.digest_hash('base64')
862866
digest: str = ''.join(['sha=', sha_1])
863-
committed_session: Files = self.create_file_upload_session_commit_by_url(
864-
commit_url, parts, digest
867+
committed_session: Optional[Files] = (
868+
self.create_file_upload_session_commit_by_url(commit_url, parts, digest)
865869
)
866870
return committed_session.entries[0]

box_sdk_gen/managers/downloads.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def download_file(
5050
range: Optional[str] = None,
5151
boxapi: Optional[str] = None,
5252
extra_headers: Optional[Dict[str, Optional[str]]] = None
53-
) -> ByteStream:
53+
) -> Optional[ByteStream]:
5454
"""
5555
Returns the contents of a file in binary format.
5656
:param file_id: The unique identifier that represents a file.
@@ -112,6 +112,8 @@ def download_file(
112112
network_session=self.network_session,
113113
)
114114
)
115+
if to_string(response.status) == '202':
116+
return None
115117
return response.content
116118

117119
def download_file_to_output_stream(

box_sdk_gen/managers/files.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ def get_file_thumbnail_by_id(
601601
max_height: Optional[int] = None,
602602
max_width: Optional[int] = None,
603603
extra_headers: Optional[Dict[str, Optional[str]]] = None
604-
) -> ByteStream:
604+
) -> Optional[ByteStream]:
605605
"""
606606
Retrieves a thumbnail, or smaller image representation, of a file.
607607
@@ -675,4 +675,6 @@ def get_file_thumbnail_by_id(
675675
network_session=self.network_session,
676676
)
677677
)
678+
if to_string(response.status) == '202':
679+
return None
678680
return response.content

box_sdk_gen/managers/user_collaborations.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def update_collaboration_by_id(
199199
expires_at: Optional[DateTime] = None,
200200
can_view_path: Optional[bool] = None,
201201
extra_headers: Optional[Dict[str, Optional[str]]] = None
202-
) -> Collaboration:
202+
) -> Optional[Collaboration]:
203203
"""
204204
Updates a collaboration.
205205
@@ -275,7 +275,9 @@ def update_collaboration_by_id(
275275
network_session=self.network_session,
276276
)
277277
)
278-
return deserialize(response.data, Collaboration)
278+
if to_string(response.status) == '204':
279+
return None
280+
return deserialize(response.data, Optional[Collaboration])
279281

280282
def delete_collaboration_by_id(
281283
self,

box_sdk_gen/networking/fetch.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ def fetch(options: FetchOptions) -> FetchResponse:
124124
accepted_with_retry_after = (
125125
network_response.status_code == HTTPStatus.ACCEPTED
126126
) and response.get_header('Retry-After', None)
127-
if network_response.ok and not accepted_with_retry_after:
127+
if network_response.ok and (
128+
not accepted_with_retry_after or attempt_nr >= max_attempts
129+
):
128130
if options.response_format == 'binary':
129131
return FetchResponse(
130132
status=network_response.status_code,

docs/chunked_uploads.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ client.chunked_uploads.create_file_upload_session_commit_by_url(
397397

398398
### Returns
399399

400-
This function returns a value of type `Files`.
400+
This function returns a value of type `Optional[Files]`.
401401

402402
Returns the file object in a list.Returns when all chunks have been uploaded but not yet processed.
403403

@@ -442,7 +442,7 @@ client.chunked_uploads.create_file_upload_session_commit(
442442

443443
### Returns
444444

445-
This function returns a value of type `Files`.
445+
This function returns a value of type `Optional[Files]`.
446446

447447
Returns the file object in a list.Returns when all chunks have been uploaded but not yet processed.
448448

docs/downloads.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ client.downloads.download_file(uploaded_file.id)
3535

3636
### Returns
3737

38-
This function returns a value of type `ByteStream`.
38+
This function returns a value of type `Optional[ByteStream]`.
3939

4040
Returns the requested file if the client has the **follow
4141
redirects** setting enabled to automatically

docs/files.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ client.files.get_file_thumbnail_by_id(
221221

222222
### Returns
223223

224-
This function returns a value of type `ByteStream`.
224+
This function returns a value of type `Optional[ByteStream]`.
225225

226226
When a thumbnail can be created the thumbnail data will be
227227
returned in the body of the response.Sometimes generating a thumbnail can take a few seconds. In these

docs/user_collaborations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ client.user_collaborations.update_collaboration_by_id(
7171

7272
### Returns
7373

74-
This function returns a value of type `Collaboration`.
74+
This function returns a value of type `Optional[Collaboration]`.
7575

7676
Returns an updated collaboration object unless the owner has changed.If the role is changed to `owner`, the collaboration is deleted
7777
and a new collaboration is created. The previous `owner` of

0 commit comments

Comments
 (0)