Skip to content

Commit a94dbe0

Browse files
cojencoparthea
andauthored
fix: allow recover to check the status of upload regardless of state (#343)
* fix: allow recover to check the status of upload regardless of state * fix docs lint * more lint Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent d563ec3 commit a94dbe0

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

packages/google-resumable-media/google/resumable_media/_upload.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -794,14 +794,8 @@ def _prepare_recover_request(self):
794794
The headers **do not** incorporate the ``_headers`` on the
795795
current instance.
796796
797-
Raises:
798-
ValueError: If the current upload is not in an invalid state.
799-
800797
.. _sans-I/O: https://sans-io.readthedocs.io/
801798
"""
802-
if not self.invalid:
803-
raise ValueError("Upload is not in invalid state, no need to recover.")
804-
805799
headers = {_helpers.CONTENT_RANGE_HEADER: "bytes */*"}
806800
return _PUT, self.resumable_url, None, headers
807801

packages/google-resumable-media/google/resumable_media/requests/upload.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,14 +517,15 @@ def retriable_request():
517517
)
518518

519519
def recover(self, transport):
520-
"""Recover from a failure.
521-
522-
This method should be used when a :class:`ResumableUpload` is in an
523-
:attr:`~ResumableUpload.invalid` state due to a request failure.
520+
"""Recover from a failure and check the status of the current upload.
524521
525522
This will verify the progress with the server and make sure the
526523
current upload is in a valid state before :meth:`transmit_next_chunk`
527-
can be used again.
524+
can be used again. See https://cloud.google.com/storage/docs/performing-resumable-uploads#status-check
525+
for more information.
526+
527+
This method can be used when a :class:`ResumableUpload` is in an
528+
:attr:`~ResumableUpload.invalid` state due to a request failure.
528529
529530
Args:
530531
transport (~requests.Session): A ``requests`` object which can

packages/google-resumable-media/tests/unit/test__upload.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,13 @@ def test__prepare_recover_request_not_invalid(self):
951951
upload = _upload.ResumableUpload(RESUMABLE_URL, ONE_MB)
952952
assert not upload.invalid
953953

954-
with pytest.raises(ValueError):
955-
upload._prepare_recover_request()
954+
method, url, payload, headers = upload._prepare_recover_request()
955+
assert method == "PUT"
956+
assert url == upload.resumable_url
957+
assert payload is None
958+
assert headers == {"content-range": "bytes */*"}
959+
# Make sure headers are untouched.
960+
assert upload._headers == {}
956961

957962
def test__prepare_recover_request(self):
958963
upload = _upload.ResumableUpload(RESUMABLE_URL, ONE_MB)

0 commit comments

Comments
 (0)