Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Mar 31, 2026. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 173
fix: replace default retry for upload operations#480
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
139cd2c
fix: revise upload operations preconditions to if_generation_match
cojenco b57b863
fix docstrings
cojenco 8c1ae3c
add retry configuration to blob.create_resumable_upload_session
cojenco aec585b
align var values in test
cojenco e91916f
test coverage
cojenco 6f7f3b6
Revert "test coverage"
cojenco cccc4f4
Revert "align var values in test"
cojenco 18cdc86
Revert "add retry configuration to blob.create_resumable_upload_session"
cojenco 63ec083
revise tests after reverting
cojenco 6c96e01
Merge branch 'master' into update-upload-retry-477
cojenco 75e78f3
Merge branch 'master' into update-upload-retry-477
cojenco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -82,7 +82,6 @@ | ||
| from google.cloud.storage.retry import DEFAULT_RETRY | ||
| from google.cloud.storage.retry import DEFAULT_RETRY_IF_ETAG_IN_JSON | ||
| from google.cloud.storage.retry import DEFAULT_RETRY_IF_GENERATION_SPECIFIED | ||
| from google.cloud.storage.retry import DEFAULT_RETRY_IF_METAGENERATION_SPECIFIED | ||
| from google.cloud.storage.fileio import BlobReader | ||
| from google.cloud.storage.fileio import BlobWriter | ||
| @@ -1703,10 +1702,10 @@ def _do_multipart_upload( | ||
| :type num_retries: int | ||
| :param num_retries: | ||
| Number of upload retries. By default, only uploads with | ||
| if_metageneration_match set will be retried, as uploads without the | ||
| if_generation_match set will be retried, as uploads without the | ||
| argument are not guaranteed to be idempotent. Setting num_retries | ||
| will override this default behavior and guarantee retries even when | ||
| if_metageneration_match is not set. (Deprecated: This argument | ||
| if_generation_match is not set. (Deprecated: This argument | ||
| will be removed in a future release.) | ||
| :type predefined_acl: str | ||
| @@ -1750,7 +1749,7 @@ def _do_multipart_upload( | ||
| This private method does not accept ConditionalRetryPolicy values | ||
| because the information necessary to evaluate the policy is instead | ||
| evaluated in client.download_blob_to_file(). | ||
| evaluated in blob._do_upload(). | ||
| See the retry.py source code and docstrings in this package | ||
| (google.cloud.storage.retry) for information on retry types and how | ||
| @@ -1877,10 +1876,10 @@ def _initiate_resumable_upload( | ||
| :type num_retries: int | ||
| :param num_retries: | ||
| Number of upload retries. By default, only uploads with | ||
tritone marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if_metageneration_match set will be retried, as uploads without the | ||
| if_generation_match set will be retried, as uploads without the | ||
| argument are not guaranteed to be idempotent. Setting num_retries | ||
| will override this default behavior and guarantee retries even when | ||
| if_metageneration_match is not set. (Deprecated: This argument | ||
| if_generation_match is not set. (Deprecated: This argument | ||
| will be removed in a future release.) | ||
| :type extra_headers: dict | ||
| @@ -1936,7 +1935,7 @@ def _initiate_resumable_upload( | ||
| This private method does not accept ConditionalRetryPolicy values | ||
| because the information necessary to evaluate the policy is instead | ||
| evaluated in client.download_blob_to_file(). | ||
| evaluated in blob._do_upload(). | ||
| See the retry.py source code and docstrings in this package | ||
| (google.cloud.storage.retry) for information on retry types and how | ||
| @@ -2070,10 +2069,10 @@ def _do_resumable_upload( | ||
| :type num_retries: int | ||
| :param num_retries: | ||
| Number of upload retries. By default, only uploads with | ||
| if_metageneration_match set will be retried, as uploads without the | ||
| if_generation_match set will be retried, as uploads without the | ||
| argument are not guaranteed to be idempotent. Setting num_retries | ||
| will override this default behavior and guarantee retries even when | ||
| if_metageneration_match is not set. (Deprecated: This argument | ||
| if_generation_match is not set. (Deprecated: This argument | ||
| will be removed in a future release.) | ||
| :type predefined_acl: str | ||
| @@ -2119,7 +2118,7 @@ def _do_resumable_upload( | ||
| This private method does not accept ConditionalRetryPolicy values | ||
| because the information necessary to evaluate the policy is instead | ||
| evaluated in client.download_blob_to_file(). | ||
| evaluated in blob._do_upload(). | ||
| See the retry.py source code and docstrings in this package | ||
| (google.cloud.storage.retry) for information on retry types and how | ||
| @@ -2204,10 +2203,10 @@ def _do_upload( | ||
| :type num_retries: int | ||
| :param num_retries: | ||
| Number of upload retries. By default, only uploads with | ||
| if_metageneration_match set will be retried, as uploads without the | ||
| if_generation_match set will be retried, as uploads without the | ||
| argument are not guaranteed to be idempotent. Setting num_retries | ||
| will override this default behavior and guarantee retries even when | ||
| if_metageneration_match is not set. (Deprecated: This argument | ||
| if_generation_match is not set. (Deprecated: This argument | ||
| will be removed in a future release.) | ||
| :type predefined_acl: str | ||
| @@ -2258,7 +2257,7 @@ def _do_upload( | ||
| This class exists to provide safe defaults for RPC calls that are | ||
| not technically safe to retry normally (due to potential data | ||
| duplication or other side-effects) but become safe to retry if a | ||
| condition such as if_metageneration_match is set. | ||
| condition such as if_generation_match is set. | ||
| See the retry.py source code and docstrings in this package | ||
| (google.cloud.storage.retry) for information on retry types and how | ||
| @@ -2337,7 +2336,7 @@ def upload_from_file( | ||
| if_metageneration_not_match=None, | ||
| timeout=_DEFAULT_TIMEOUT, | ||
| checksum=None, | ||
| retry=DEFAULT_RETRY_IF_METAGENERATION_SPECIFIED, | ||
| retry=DEFAULT_RETRY_IF_GENERATION_SPECIFIED, | ||
| ): | ||
| """Upload the contents of this blob from a file-like object. | ||
| @@ -2397,10 +2396,10 @@ def upload_from_file( | ||
| :type num_retries: int | ||
| :param num_retries: | ||
| Number of upload retries. By default, only uploads with | ||
| if_metageneration_match set will be retried, as uploads without the | ||
| if_generation_match set will be retried, as uploads without the | ||
| argument are not guaranteed to be idempotent. Setting num_retries | ||
| will override this default behavior and guarantee retries even when | ||
| if_metageneration_match is not set. (Deprecated: This argument | ||
| if_generation_match is not set. (Deprecated: This argument | ||
| will be removed in a future release.) | ||
| :type client: :class:`~google.cloud.storage.client.Client` | ||
| @@ -2456,7 +2455,7 @@ def upload_from_file( | ||
| This class exists to provide safe defaults for RPC calls that are | ||
| not technically safe to retry normally (due to potential data | ||
| duplication or other side-effects) but become safe to retry if a | ||
| condition such as if_metageneration_match is set. | ||
| condition such as if_generation_match is set. | ||
| See the retry.py source code and docstrings in this package | ||
| (google.cloud.storage.retry) for information on retry types and how | ||
| @@ -2479,7 +2478,7 @@ def upload_from_file( | ||
| # num_retries and retry are mutually exclusive. If num_retries is | ||
| # set and retry is exactly the default, then nullify retry for | ||
| # backwards compatibility. | ||
| if retry is DEFAULT_RETRY_IF_METAGENERATION_SPECIFIED: | ||
| if retry is DEFAULT_RETRY_IF_GENERATION_SPECIFIED: | ||
| retry = None | ||
| _maybe_rewind(file_obj, rewind=rewind) | ||
| @@ -2518,7 +2517,7 @@ def upload_from_filename( | ||
| if_metageneration_not_match=None, | ||
| timeout=_DEFAULT_TIMEOUT, | ||
| checksum=None, | ||
| retry=DEFAULT_RETRY_IF_METAGENERATION_SPECIFIED, | ||
| retry=DEFAULT_RETRY_IF_GENERATION_SPECIFIED, | ||
| ): | ||
| """Upload this blob's contents from the content of a named file. | ||
| @@ -2558,10 +2557,10 @@ def upload_from_filename( | ||
| :type num_retries: int | ||
| :param num_retries: | ||
| Number of upload retries. By default, only uploads with | ||
| if_metageneration_match set will be retried, as uploads without the | ||
| if_generation_match set will be retried, as uploads without the | ||
| argument are not guaranteed to be idempotent. Setting num_retries | ||
| will override this default behavior and guarantee retries even when | ||
| if_metageneration_match is not set. (Deprecated: This argument | ||
| if_generation_match is not set. (Deprecated: This argument | ||
| will be removed in a future release.) | ||
| :type predefined_acl: str | ||
| @@ -2612,7 +2611,7 @@ def upload_from_filename( | ||
| This class exists to provide safe defaults for RPC calls that are | ||
| not technically safe to retry normally (due to potential data | ||
| duplication or other side-effects) but become safe to retry if a | ||
| condition such as if_metageneration_match is set. | ||
| condition such as if_generation_match is set. | ||
| See the retry.py source code and docstrings in this package | ||
| (google.cloud.storage.retry) for information on retry types and how | ||
| @@ -2656,7 +2655,7 @@ def upload_from_string( | ||
| if_metageneration_not_match=None, | ||
| timeout=_DEFAULT_TIMEOUT, | ||
| checksum=None, | ||
| retry=DEFAULT_RETRY_IF_METAGENERATION_SPECIFIED, | ||
| retry=DEFAULT_RETRY_IF_GENERATION_SPECIFIED, | ||
| ): | ||
| """Upload contents of this blob from the provided string. | ||
| @@ -2687,10 +2686,10 @@ def upload_from_string( | ||
| :type num_retries: int | ||
| :param num_retries: | ||
| Number of upload retries. By default, only uploads with | ||
| if_metageneration_match set will be retried, as uploads without the | ||
| if_generation_match set will be retried, as uploads without the | ||
| argument are not guaranteed to be idempotent. Setting num_retries | ||
| will override this default behavior and guarantee retries even when | ||
| if_metageneration_match is not set. (Deprecated: This argument | ||
| if_generation_match is not set. (Deprecated: This argument | ||
| will be removed in a future release.) | ||
| :type client: :class:`~google.cloud.storage.client.Client` | ||
| @@ -2746,7 +2745,7 @@ def upload_from_string( | ||
| This class exists to provide safe defaults for RPC calls that are | ||
| not technically safe to retry normally (due to potential data | ||
| duplication or other side-effects) but become safe to retry if a | ||
| condition such as if_metageneration_match is set. | ||
| condition such as if_generation_match is set. | ||
| See the retry.py source code and docstrings in this package | ||
| (google.cloud.storage.retry) for information on retry types and how | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it looks like we're evaluating it BOTH in blob._do_upload() and in client.download_blob_to_file(). This is harmless, which is why the tests didn't catch it, but we only need one of those.
I don't have a strong opinion on whether we do this in _do_upload or download_blob_to_file. Let's keep this docstring change and additionally we can remove the conditional retry policy code in client.download_blob_to_file, either in another PR, or in this one if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, I believe we'll need to remain both ConditionalRetryPolicy evaluations as one is for upload operations and the other is for downloads. I revised the docstrings here to match particularly where we're doing the evaluations for upload operations,
blob._do_upload().