Skip to content
Permalink
Browse files
fix: add ConnectionError to default retry (#571)
  • Loading branch information
tswast committed Mar 23, 2021
1 parent 8f274e8 commit a3edb8b921e029e2c03d33302d408ad5d4e9d4ad
Showing with 15 additions and 4 deletions.
  1. +4 −4 google/cloud/bigquery/retry.py
  2. +1 −0 setup.py
  3. +1 −0 testing/constraints-3.6.txt
  4. +9 −0 tests/unit/test_retry.py
@@ -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,
)


@@ -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)

@@ -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": [
@@ -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
@@ -15,6 +15,7 @@
import unittest

import mock
import requests.exceptions


class Test_should_retry(unittest.TestCase):
@@ -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

0 comments on commit a3edb8b

Please sign in to comment.