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 — fix: add ConnectionError to default retry by cojenco · Pull Request #445 · googleapis/python-storage

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

Conversation

@cojenco

@cojenco cojenco commented May 17, 2021

Copy link
Copy Markdown
Contributor

This adds python built-in ConnectionError to default retryable types.
ConnectionError was recently added in the BigQuery library to allow retries.

Fixes #426 🦕

Sorry, something went wrong.

Uh oh!

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

All reactions
@cojenco
fix: add ConnectionError to default retry
79c29d5
@cojenco
cojenco requested review from a team May 17, 2021 17:45
@product-auto-label product-auto-label Bot added the api: storage Issues related to the googleapis/python-storage API. label May 17, 2021
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label May 17, 2021
@cojenco
cojenco marked this pull request as draft May 18, 2021 04:33
tritone
tritone reviewed May 18, 2021
View reviewed changes

@tritone tritone left a comment •
edited
Loading

Uh oh!

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

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.

thanks!

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread google/cloud/storage/retry.py Outdated


_RETRYABLE_TYPES = (
ConnectionError,

@tritone tritone May 18, 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.

ConnectionError has a bunch of subclasses: https://docs.python.org/3/library/exceptions.html#ConnectionError . Just wanted to confirm that we consider all of these retryable?

Also, is there a test where we should add this as a test case?

Sorry, something went wrong.

Uh oh!

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

cojenco reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@tseaver tseaver May 18, 2021 •
edited
Loading

Uh oh!

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

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.

One or more tests should be added to the Test_should_retry class in tests/unit/test_retry.py (see the BigQuery PR for examples).

Also, that PR makes requests.exceptions.ConnectionError an explicit retryable type. The requests version does not derive from the stdlib type:

$ .nox/unit-3-9/bin/python
Python 3.9.0 (default, Apr 20 2021, 11:50:03) 
[GCC 9.3.0] on linux
>>> import requests.exceptions
>>> requests.exceptions.ConnectionError
<class 'requests.exceptions.ConnectionError'>
>>> requests.exceptions.ConnectionError.__mro__
(<class 'requests.exceptions.ConnectionError'>, <class 'requests.exceptions.RequestException'>, <class 'OSError'>, <class 'Exception'>, <class 'BaseException'>, <class 'object'>)

Sorry, something went wrong.

Uh oh!

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

All reactions

@tseaver tseaver May 18, 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.

Note that ConnectionError is not a stdlib type in Python 2.7:

$ .nox/unit-2-7/bin/python
Python 2.7.17 (default, Apr 20 2021, 14:27:04) 
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> ConnectionError
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'ConnectionError' is not defined

We need to do something like:

try:
    _RETRYABLE_STDLIB_TYPES = {ConnectionError,)
except NameError:
    _RETRYABLE_STDLIB_TYPES = {}

and then, below:

RETRYABLE_TYPES = _RETRYABLE_STDLIB_TYPES + (
    api_exceptions.TooManyRequests,  # 429
    ...
)

Sorry, something went wrong.

Uh oh!

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

cojenco reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@cojenco cojenco May 18, 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.

@tritone @tseaver Thanks for reviewing! Looking at the python3 docs and previous discussion in the Big Query, ConnectionError and its subclasses are retryable. From users feedback, this error occurs when there are multiple Cloud Functions running and/or subsequent reinvocation of Cloud Functions. The retry test is set up with a loop that tests each default retry. I'll double check to make the changes and add one or more specific tests. Thanks!

Sorry, something went wrong.

Uh oh!

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

All reactions

@cojenco cojenco May 18, 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.

@tseaver I noticed that ConnectionError is not a stdlib type in Python 2.7 upon submission. Changed PR to draft to implement changes. This is exactly what I need. Thanks so much for the pointers!

Sorry, something went wrong.

Uh oh!

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

All reactions
tseaver
tseaver suggested changes May 18, 2021
View reviewed changes
Comment thread google/cloud/storage/retry.py Outdated


_RETRYABLE_TYPES = (
ConnectionError,

@tseaver tseaver May 18, 2021 •
edited
Loading

Uh oh!

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

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.

One or more tests should be added to the Test_should_retry class in tests/unit/test_retry.py (see the BigQuery PR for examples).

Also, that PR makes requests.exceptions.ConnectionError an explicit retryable type. The requests version does not derive from the stdlib type:

$ .nox/unit-3-9/bin/python
Python 3.9.0 (default, Apr 20 2021, 11:50:03) 
[GCC 9.3.0] on linux
>>> import requests.exceptions
>>> requests.exceptions.ConnectionError
<class 'requests.exceptions.ConnectionError'>
>>> requests.exceptions.ConnectionError.__mro__
(<class 'requests.exceptions.ConnectionError'>, <class 'requests.exceptions.RequestException'>, <class 'OSError'>, <class 'Exception'>, <class 'BaseException'>, <class 'object'>)

Sorry, something went wrong.

Uh oh!

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

All reactions
tseaver
tseaver suggested changes May 18, 2021
View reviewed changes
Comment thread google/cloud/storage/retry.py Outdated


_RETRYABLE_TYPES = (
ConnectionError,

@tseaver tseaver May 18, 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.

Note that ConnectionError is not a stdlib type in Python 2.7:

$ .nox/unit-2-7/bin/python
Python 2.7.17 (default, Apr 20 2021, 14:27:04) 
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> ConnectionError
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'ConnectionError' is not defined

We need to do something like:

try:
    _RETRYABLE_STDLIB_TYPES = {ConnectionError,)
except NameError:
    _RETRYABLE_STDLIB_TYPES = {}

and then, below:

RETRYABLE_TYPES = _RETRYABLE_STDLIB_TYPES + (
    api_exceptions.TooManyRequests,  # 429
    ...
)

Sorry, something went wrong.

Uh oh!

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

cojenco reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
cojenco added 2 commits May 18, 2021 13:48
@cojenco
add _RETRYABLE_STDLIB_TYPES to address ConnectionError not in python2
67c2b22
@cojenco
add test for ConnectionError default retries
4477757
@cojenco
cojenco marked this pull request as ready for review May 19, 2021 16:56
@cojenco
cojenco requested review from tritone and tseaver May 19, 2021 17:23
tseaver
tseaver suggested changes May 19, 2021
View reviewed changes
Comment thread tests/unit/test_retry.py Resolved

Uh oh!

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

tritone
tritone reviewed May 19, 2021
View reviewed changes
Comment thread tests/unit/test_retry.py Resolved

Uh oh!

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

Comment thread tests/unit/test_retry.py Resolved

Uh oh!

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

@cojenco
rename test_miss_w_stdlib_error and update test_w_requests_connection…
e7cc759
…_error
@google-cla

google-cla Bot commented May 19, 2021

Copy link
Copy Markdown

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

All reactions

Sorry, something went wrong.

Uh oh!

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

@google-cla google-cla Bot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels May 19, 2021
@google-cla

google-cla Bot commented May 19, 2021

Copy link
Copy Markdown

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

All reactions

Sorry, something went wrong.

Uh oh!

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

@tseaver

tseaver commented May 19, 2021

Copy link
Copy Markdown
Contributor

@googlebot I fixed it.

All reactions

Sorry, something went wrong.

Uh oh!

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

@google-cla

google-cla Bot commented May 19, 2021

Copy link
Copy Markdown

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

All reactions

Sorry, something went wrong.

Uh oh!

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

@cojenco

cojenco commented May 19, 2021

Copy link
Copy Markdown
Contributor Author

@googlebot I fixed it.

All reactions

Sorry, something went wrong.

Uh oh!

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

@google-cla

google-cla Bot commented May 19, 2021

Copy link
Copy Markdown

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

All reactions

Sorry, something went wrong.

Uh oh!

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

@tseaver

tseaver commented May 19, 2021

Copy link
Copy Markdown
Contributor

@cojenco I don't know what the CLAbot is on about. As a Googler, I believe you can manually clear the cla: no label and set cla: yes instead.

All reactions

Sorry, something went wrong.

Uh oh!

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

@cojenco cojenco added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels May 19, 2021
@cojenco

cojenco commented May 19, 2021

Copy link
Copy Markdown
Contributor Author

Thanks @tseaver! Manually added the cla label. I'm looking at my configs. So when I commited the suggestion directly on Github, the email logged was a <users.noreply.github.com> account.

All reactions

Sorry, something went wrong.

Uh oh!

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

@cojenco cojenco added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 19, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 19, 2021
@tseaver

tseaver commented May 19, 2021

Copy link
Copy Markdown
Contributor

Ugh, I tested that syntax at the Python command prompt, where __buitins__ is a module. Per the Python docs for the builtins module, we should probably not rely on it being either the module or its dict, and instead move to something like:

try:
    ConnectionError
except NameError:
    _HAS_CONNECTION_ERROR = False
else:
    _HAS_CONNECTION_ERROR = True

and then use that flag to control the skip:

    @unittest.skipUnless(_HAS_CONNECTION_ERROR, "...")

Since my suggestion didn't work out, and messed up the CLAbot, maybe it would be best to rebase away
bcfe2be and start fresh.

cojenco reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

renovate-bot and others added 2 commits May 19, 2021 15:25
@renovate-bot @cojenco
chore(deps): update precommit hook pre-commit/pre-commit-hooks to v4 (#…
c37d6bb
…444)

[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [pre-commit/pre-commit-hooks](https://togithub.com/pre-commit/pre-commit-hooks) | repository | major | `v3.4.0` -> `v4.0.1` |

---

### Release Notes

<details>
<summary>pre-commit/pre-commit-hooks</summary>

### [`v4.0.1`](https://togithub.com/pre-commit/pre-commit-hooks/releases/v4.0.1)

[Compare Source](https://togithub.com/pre-commit/pre-commit-hooks/compare/v4.0.0...v4.0.1)

##### Fixes

-   `check-shebang-scripts-are-executable` fix entry point.
    -   [#&#8203;602](https://togithub.com/pre-commit/pre-commit-hooks/issues/602) issue by [@&#8203;Person-93](https://togithub.com/Person-93).
    -   [#&#8203;603](https://togithub.com/pre-commit/pre-commit-hooks/issues/603) PR by [@&#8203;scop](https://togithub.com/scop).

### [`v4.0.0`](https://togithub.com/pre-commit/pre-commit-hooks/releases/v4.0.0)

[Compare Source](https://togithub.com/pre-commit/pre-commit-hooks/compare/v3.4.0...v4.0.0)

##### Features

-   `check-json`: report duplicate keys.
    -   [#&#8203;558](https://togithub.com/pre-commit/pre-commit-hooks/issues/558) PR by [@&#8203;AdityaKhursale](https://togithub.com/AdityaKhursale).
    -   [#&#8203;554](https://togithub.com/pre-commit/pre-commit-hooks/issues/554) issue by [@&#8203;adamchainz](https://togithub.com/adamchainz).
-   `no-commit-to-branch`: add `main` to default blocked branches.
    -   [#&#8203;565](https://togithub.com/pre-commit/pre-commit-hooks/issues/565) PR by [@&#8203;ndevenish](https://togithub.com/ndevenish).
-   `check-case-conflict`: check conflicts in directory names as well.
    -   [#&#8203;575](https://togithub.com/pre-commit/pre-commit-hooks/issues/575) PR by [@&#8203;slsyy](https://togithub.com/slsyy).
    -   [#&#8203;70](https://togithub.com/pre-commit/pre-commit-hooks/issues/70) issue by [@&#8203;andyjack](https://togithub.com/andyjack).
-   `check-vcs-permalinks`: forbid other branch names.
    -   [#&#8203;582](https://togithub.com/pre-commit/pre-commit-hooks/issues/582) PR by [@&#8203;jack1142](https://togithub.com/jack1142).
    -   [#&#8203;581](https://togithub.com/pre-commit/pre-commit-hooks/issues/581) issue by [@&#8203;jack1142](https://togithub.com/jack1142).
-   `check-shebang-scripts-are-executable`: new hook which ensures shebang'd scripts are executable.
    -   [#&#8203;545](https://togithub.com/pre-commit/pre-commit-hooks/issues/545) PR by [@&#8203;scop](https://togithub.com/scop).

##### Fixes

-   `check-executables-have-shebangs`: Short circuit shebang lookup on windows.
    -   [#&#8203;544](https://togithub.com/pre-commit/pre-commit-hooks/issues/544) PR by [@&#8203;scop](https://togithub.com/scop).
-   `requirements-txt-fixer`: Fix comments which have indentation
    -   [#&#8203;549](https://togithub.com/pre-commit/pre-commit-hooks/issues/549) PR by [@&#8203;greshilov](https://togithub.com/greshilov).
    -   [#&#8203;548](https://togithub.com/pre-commit/pre-commit-hooks/issues/548) issue by [@&#8203;greshilov](https://togithub.com/greshilov).
-   `pretty-format-json`: write to stdout using UTF-8 encoding.
    -   [#&#8203;571](https://togithub.com/pre-commit/pre-commit-hooks/issues/571) PR by [@&#8203;jack1142](https://togithub.com/jack1142).
    -   [#&#8203;570](https://togithub.com/pre-commit/pre-commit-hooks/issues/570) issue by [@&#8203;jack1142](https://togithub.com/jack1142).
-   Use more inclusive language.
    -   [#&#8203;599](https://togithub.com/pre-commit/pre-commit-hooks/issues/599) PR by [@&#8203;asottile](https://togithub.com/asottile).

##### Breaking changes

-   Remove deprecated hooks: `flake8`, `pyflakes`, `autopep8-wrapper`.
    -   [#&#8203;597](https://togithub.com/pre-commit/pre-commit-hooks/issues/597) PR by [@&#8203;asottile](https://togithub.com/asottile).

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻️ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/python-storage).
@cojenco
skip testcase stdlib ConnectionError on Python2
9d7f594
@cojenco
cojenco force-pushed the connection-426 branch from 581fdce to 9d7f594 Compare May 19, 2021 23:17
@cojenco
Merge branch 'master' into connection-426
eab5274
@cojenco
cojenco requested a review from tseaver May 19, 2021 23:53
tseaver
tseaver approved these changes May 20, 2021
View reviewed changes
@tseaver
Merge branch 'master' into connection-426
42b0b6e
@tseaver tseaver added the automerge Merge the pull request once unit tests and other checks pass. label May 20, 2021
tritone
tritone approved these changes May 20, 2021
View reviewed changes
@gcf-merge-on-green
gcf-merge-on-green Bot merged commit 8344253 into master May 20, 2021
@gcf-merge-on-green
gcf-merge-on-green Bot deleted the connection-426 branch May 20, 2021 15:26
@gcf-merge-on-green gcf-merge-on-green Bot removed the automerge Merge the pull request once unit tests and other checks pass. label May 20, 2021
cojenco added a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
@cojenco
fix: add ConnectionError to default retry (googleapis#445)
f072f3d
This adds python built-in [ConnectionError](https://docs.python.org/3/library/exceptions.html#ConnectionError) to default retryable types. 
ConnectionError was recently added in the [BigQuery library](googleapis/python-bigquery#571) to allow retries. 

Fixes googleapis#426 🦕
cojenco added a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
@cojenco
fix: add ConnectionError to default retry (googleapis#445)
daac538
This adds python built-in [ConnectionError](https://docs.python.org/3/library/exceptions.html#ConnectionError) to default retryable types. 
ConnectionError was recently added in the [BigQuery library](googleapis/python-bigquery#571) to allow retries. 

Fixes googleapis#426 🦕
@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

2 more reviewers
@tseaver tseaver tseaver approved these changes
@tritone tritone tritone 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.

Add Python ConnectionError in list of retry

Uh oh!

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

5 participants

@cojenco @tseaver @tritone @yoshi-kokoro @renovate-bot
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.