Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add ConnectionError to default retry #571

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions google/cloud/bigquery/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@

from google.api_core import exceptions
from google.api_core import retry
import requests.exceptions


_RETRYABLE_REASONS = frozenset(
["rateLimitExceeded", "backendError", "internalError", "badGateway"]
)

_UNSTRUCTURED_RETRYABLE_TYPES = (
ConnectionError,
exceptions.TooManyRequests,
exceptions.InternalServerError,
exceptions.BadGateway,
requests.exceptions.ConnectionError,
)


Expand All @@ -33,10 +36,7 @@ def _should_retry(exc):
We retry if and only if the 'reason' is 'backendError'
or 'rateLimitExceeded'.
"""
if not hasattr(exc, "errors"):
return False

if len(exc.errors) == 0:
if not hasattr(exc, "errors") or len(exc.errors) == 0:
# Check for unstructured error returns, e.g. from GFE
return isinstance(exc, _UNSTRUCTURED_RETRYABLE_TYPES)

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"google-resumable-media >= 0.6.0, < 2.0dev",
"packaging >= 14.3",
"protobuf >= 3.12.0",
"requests >= 2.18.0, < 3.0.0dev",
]
extras = {
"bqstorage": [
Expand Down
1 change: 1 addition & 0 deletions testing/constraints-3.6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ pandas==0.23.0
proto-plus==1.10.0
protobuf==3.12.0
pyarrow==1.0.0
requests==2.18.0
six==1.13.0
tqdm==4.7.4
9 changes: 9 additions & 0 deletions tests/unit/test_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import unittest

import mock
import requests.exceptions


class Test_should_retry(unittest.TestCase):
Expand Down Expand Up @@ -42,6 +43,14 @@ def test_w_rateLimitExceeded(self):
exc = mock.Mock(errors=[{"reason": "rateLimitExceeded"}], spec=["errors"])
self.assertTrue(self._call_fut(exc))

def test_w_unstructured_connectionerror(self):
exc = ConnectionError()
self.assertTrue(self._call_fut(exc))

def test_w_unstructured_requests_connectionerror(self):
exc = requests.exceptions.ConnectionError()
self.assertTrue(self._call_fut(exc))

def test_w_unstructured_too_many_requests(self):
from google.api_core.exceptions import TooManyRequests

Expand Down