Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit 291cfe9

Browse files
authored
Update retry.py
Added debug level logging to respond to comment and cleaned up some comments.
1 parent f62c42b commit 291cfe9

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

google/cloud/bigquery/retry.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import logging
16+
1517
from google.api_core import exceptions
1618
from google.api_core import retry
1719
import google.api_core.future.polling
1820
from google.auth import exceptions as auth_exceptions # type: ignore
1921
import requests.exceptions
2022

23+
_LOGGER = logging.getLogger(__name__)
2124

2225
_RETRYABLE_REASONS = frozenset(
2326
["rateLimitExceeded", "backendError", "internalError", "badGateway"]
@@ -61,14 +64,15 @@
6164
def _should_retry(exc):
6265
"""Predicate for determining when to retry.
6366
64-
We retry if and only if the 'reason' is 'backendError'
65-
or 'rateLimitExceeded'.
67+
We retry if and only if the 'reason' is in _RETRYABLE_REASONS or is
68+
in _UNSTRUCTURED_RETRYABLE_TYPES.
6669
"""
6770
try:
6871
reason = exc.errors[0]["reason"]
6972
except (AttributeError, IndexError, TypeError, KeyError):
7073
# Fallback for when errors attribute is missing, empty, or not a dict
7174
# or doesn't contain "reason" (e.g. gRPC exceptions).
75+
_LOGGER.debug("Inspecting unstructured error for retry: %r", exc)
7276
return isinstance(exc, _UNSTRUCTURED_RETRYABLE_TYPES)
7377

7478
return reason in _RETRYABLE_REASONS

0 commit comments

Comments
 (0)