GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: media operation retries can be configured using the same interface as with non-media operation by andrewsg · Pull Request #447 · googleapis/python-storage

This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Conversation

@andrewsg

@andrewsg andrewsg commented May 20, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

All media operation calls (downloads and uploads) can be configured with Retry objects and ConditionalRetryPolicy objects, nearly identically to non-media operations. This is accomplished by converting the Retry object to a google-resumable-media-python library RetryStrategy object at the point of entry to that library.

Custom predicates of Retry objects (for instance set with Retry(predicate=...)) are not supported for media operations; they will be replaced with a media-operation-specific predicate.

This change is backwards-compatible for users of public methods using num_retries arguments to configure uploads; num_retries continue to be supported but the deprecation warning remains in effect. They will be fully removed and replaced with Retry objects in the future.

With this change, the default parameters for a media operations retry changes to be uniform with non-media operation retries. Specifically, the retry deadline for media operation retries becomes 120 seconds unless otherwise configured.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
andrewsg added 6 commits March 30, 2021 11:25
@andrewsg
fix: Ensure consistency check in test runs even if expected error occurs
9a0eede
@andrewsg
tests pass
f43f630
@andrewsg
tests pass with refactor
0d3d260
@andrewsg
version bump for dependencies; tests pass for real now
265d3bc
@andrewsg
complete tests for download retries
a820538
@andrewsg
coverage and test
20afb8e
@andrewsg
andrewsg requested review from a team, cojenco, frankyn and tseaver May 20, 2021 23:47
@product-auto-label product-auto-label Bot added the api: storage Issues related to the googleapis/python-storage API. label May 20, 2021
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label May 20, 2021
@andrewsg

andrewsg commented May 20, 2021

Copy link
Copy Markdown
Contributor Author

Tests and coverage are complete here, but docstrings are still WIP. It should be ready to be reviewed except for the docstrings. I'll mark as DNS to ensure it's not submitted without documentation complete.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrewsg andrewsg added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label May 20, 2021
@frankyn
frankyn requested a review from tritone May 21, 2021 17:14
frankyn
frankyn suggested changes May 24, 2021
View reviewed changes
Comment thread google/cloud/storage/_helpers.py
raise ValueError("num_retries and retry arguments are mutually exclusive")

elif retry is not None:
return resumable_media.RetryStrategy(

@frankyn frankyn May 24, 2021

Copy link
Copy Markdown
Contributor

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.

It looks like error types are not translatable in this case?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@andrewsg andrewsg May 24, 2021

Copy link
Copy Markdown
Contributor Author

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.

You mean custom predicates? Yes, those are not translatable. It'll be documented wherever possible.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/cloud/storage/blob.py
end=end,
checksum=checksum,
)
download._retry_strategy = retry_strategy

@frankyn frankyn May 24, 2021

Copy link
Copy Markdown
Contributor

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, this is accessing a private variable maiintained in ResumableMedia, should resumable media expose a mutable setting instead?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@andrewsg andrewsg May 24, 2021

Copy link
Copy Markdown
Contributor Author

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.

Yeah, I noticed that. This is the private variable we were already manipulating in our code (that was how num_retries was implemented). I don't know the history behind that. In the interest of keeping this PR small I chose not to refactor that. If we are confident about our interface we could potentially expose this in the Download and Upload constructors instead.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/cloud/storage/blob.py
to configure them.
"""

retry_strategy = _api_core_retry_to_resumable_media_retry(retry)

@frankyn frankyn May 24, 2021

Copy link
Copy Markdown
Contributor

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.

Would it be reasonable to expose a configurable option for mutating which errors are retried in ResumableMedia package or a pass in a lambda?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@andrewsg andrewsg May 24, 2021

Copy link
Copy Markdown
Contributor Author

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.

I did think about that, but because both error codes and exceptions are covered, they're covered in slightly different ways and exceptions are mutated through the libraries we're using in the transport layer, I felt it was not practical for this PR. We would need to think about a more comprehensive unification of code or else an abstraction of the exceptions and error codes for that to work.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
tritone
tritone reviewed May 24, 2021
View reviewed changes
Comment thread google/cloud/storage/_helpers.py
def _api_core_retry_to_resumable_media_retry(retry, num_retries=None):
"""Convert google.api.core.Retry to google.resumable_media.RetryStrategy.

Custom predicates are not translated.

@tritone tritone May 24, 2021

Copy link
Copy Markdown
Contributor

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.

Is this clear to the end user?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@andrewsg andrewsg May 24, 2021

Copy link
Copy Markdown
Contributor Author

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.

I'll have this warning in every single public method docstring, so with that it should be clear.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/cloud/storage/blob.py

:type retry: google.api_core.retry.Retry
:param retry: (Optional) How to retry the RPC. A None value will disable
retries. A google.api_core.retry.Retry value will enable retries,

@tritone tritone May 24, 2021

Copy link
Copy Markdown
Contributor

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.

Does this change the default behavior to be no retries? I would expect the default value for this retry strategy to be some reasonable standard policy rather than None. Or is this okay here because the method is not one that end users will call directly?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@andrewsg andrewsg May 24, 2021

Copy link
Copy Markdown
Contributor Author

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.

That last bit is correct; private methods such as this one don't have a retry default, but public methods do and they pass them through.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/cloud/storage/blob.py
# arguments into query_params dictionaries. Media operations work
# differently, so here we make a "fake" query_params to feed to the
# ConditionalRetryPolicy.
query_params = {

@tritone tritone May 24, 2021

Copy link
Copy Markdown
Contributor

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.

If if_generation_match and if_metageneration_match are not set, will the values in this dict be 0 or None? I'm a little confused because the docstring indicates that the param is optional but the type is listed aslong.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@andrewsg andrewsg May 24, 2021

Copy link
Copy Markdown
Contributor Author

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.

They will be None. Optional in the docstring means it may be either the declared type or None.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@frankyn
frankyn self-requested a review June 9, 2021 18:13
cojenco
cojenco reviewed Jun 10, 2021
View reviewed changes
Comment thread google/cloud/storage/blob.py
num_retries = 0

# Handle ConditionalRetryPolicy.
if isinstance(retry, ConditionalRetryPolicy):

@cojenco cojenco Jun 10, 2021

Copy link
Copy Markdown
Contributor

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.

Will there be cases where if_metageneration_match is not None and retry=None? Or is it not a concern to this private method? IIUC, it seems like if_metageneration_match will be picked up as query params in the upload url eventually, but at the same time we will have retry as resumable_media.RetryStrategy(max_retries=0)? Will the conditional retry still be triggered?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@andrewsg andrewsg Jun 11, 2021

Copy link
Copy Markdown
Contributor Author

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.

Yes, if_metageneration_match not being None and retry being None is a valid state here. query_params inside this conditional only exists for the purpose of evaluating a ConditionalRetryPolicy. In any scenario where there is no ConditionalRetryPolicy, this code will not fire, but if_generation_match and if_metageneration_match will still be consumed properly and added to the request later in the process.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@snippet-bot

snippet-bot Bot commented Jun 11, 2021

Copy link
Copy Markdown

No region tags are edited in this PR.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrewsg andrewsg removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jun 11, 2021
@andrewsg
Finish coverage and add docstrings
4b37672
@andrewsg
andrewsg force-pushed the retry-unification branch from 3caedef to 4b37672 Compare June 11, 2021 00:57
@andrewsg

andrewsg commented Jun 11, 2021

Copy link
Copy Markdown
Contributor Author

Currently working through some absolutely brutal test merge conflicts, will ask for further review when done.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrewsg
very challenging merge
c051371
@andrewsg

andrewsg commented Jun 11, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

@frankyn @tritone @cojenco PTAL. Docstrings added, all comments responded to, merge conflict resolved.

@tseaver As discussed in chat, also PTAL due to significant potential for error on my part in resolving blob method -> client method-related merge conflicts.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tseaver
tseaver reviewed Jun 11, 2021
View reviewed changes
Comment thread google/cloud/storage/client.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/unit/test_client.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/unit/test_client.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/unit/test__helpers.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/unit/test_client.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/unit/test_client.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/unit/test_fileio.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/unit/test_fileio.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/unit/test_fileio.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/unit/test_fileio.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@andrewsg
address tseaver comments
39f03b1
@andrewsg

andrewsg commented Jun 11, 2021

Copy link
Copy Markdown
Contributor Author

@tseaver PTAL. Thank you for your attention, I have much more confidence in the merge now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tseaver
tseaver approved these changes Jun 11, 2021
View reviewed changes
@tseaver tseaver mentioned this pull request Jun 11, 2021
docs: streamline docstrings for conditional parmas #464
Merged
frankyn
frankyn approved these changes Jun 11, 2021
View reviewed changes

@frankyn frankyn left a comment

Copy link
Copy Markdown
Contributor

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.

LGTM, thanks Andrew!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@andrewsg
andrewsg merged commit 0dbbb8a into master Jun 11, 2021
@andrewsg
andrewsg deleted the retry-unification branch June 11, 2021 22:26
@cojenco cojenco mentioned this pull request Jun 29, 2021
feat: add preconditions and retry configuration to blob.create_resumable_upload_session #484
Merged
cojenco pushed a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
@andrewsg @cojenco
feat: media operation retries can be configured using the same interf…
faafa09
…ace as with non-media operation (googleapis#447)

All media operation calls (downloads and uploads) can be configured with Retry objects and ConditionalRetryPolicy objects, nearly identically to non-media operations. This is accomplished by converting the Retry object to a google-resumable-media-python library RetryStrategy object at the point of entry to that library.

Custom predicates of Retry objects (for instance set with Retry(predicate=...)) are not supported for media operations; they will be replaced with a media-operation-specific predicate.

This change is backwards-compatible for users of public methods using num_retries arguments to configure uploads; num_retries continue to be supported but the deprecation warning remains in effect. They will be fully removed and replaced with Retry objects in the future.

With this change, the default parameters for a media operations retry changes to be uniform with non-media operation retries. Specifically, the retry deadline for media operation retries becomes 120 seconds unless otherwise configured.
cojenco pushed a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
@andrewsg @cojenco
feat: media operation retries can be configured using the same interf…
89e3aec
…ace as with non-media operation (googleapis#447)

All media operation calls (downloads and uploads) can be configured with Retry objects and ConditionalRetryPolicy objects, nearly identically to non-media operations. This is accomplished by converting the Retry object to a google-resumable-media-python library RetryStrategy object at the point of entry to that library.

Custom predicates of Retry objects (for instance set with Retry(predicate=...)) are not supported for media operations; they will be replaced with a media-operation-specific predicate.

This change is backwards-compatible for users of public methods using num_retries arguments to configure uploads; num_retries continue to be supported but the deprecation warning remains in effect. They will be fully removed and replaced with Retry objects in the future.

With this change, the default parameters for a media operations retry changes to be uniform with non-media operation retries. Specifically, the retry deadline for media operation retries becomes 120 seconds unless otherwise configured.
@tswast tswast mentioned this pull request Nov 18, 2021
Remove num_retries parameter from load_table_from_*() methods googleapis/google-cloud-python#15735
Closed
@release-please release-please Bot mentioned this pull request Jan 12, 2022
chore(main): release 3.0.0 #688
Closed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

4 more reviewers
@tritone tritone tritone left review comments
@cojenco cojenco cojenco left review comments
@tseaver tseaver tseaver approved these changes
@frankyn frankyn frankyn approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

api: storage Issues related to the googleapis/python-storage API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@andrewsg @tseaver @frankyn @tritone @cojenco
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.