Skip to content
Open
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
2 changes: 1 addition & 1 deletion google/genai/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def retry_args(options: Optional[HttpRetryOptions]) -> _common.StringDict:
retriable_codes = options.http_status_codes or _RETRY_HTTP_STATUS_CODES
retry = tenacity.retry_if_exception(
lambda e: (isinstance(e, errors.APIError) and e.code in retriable_codes)
or isinstance(e, _HTTPX_TRANSIENT_EXC),
or isinstance(e, _HTTPX_TRANSIENT_EXC + (auth_exceptions.TransportError,)),
)
wait = tenacity.wait_exponential_jitter(
initial=options.initial_delay or _RETRY_INITIAL_DELAY,
Expand Down
8 changes: 8 additions & 0 deletions google/genai/tests/client/test_retries.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from collections.abc import Sequence
import datetime
from unittest import mock

from google.auth import exceptions as auth_exceptions
import pytest

try:
Expand Down Expand Up @@ -204,6 +206,12 @@ def test_retry_args_retries_httpx_transport_errors():
assert not retry.predicate(ValueError('not a transport error'))


def test_retry_args_retries_google_auth_transport_errors():
args = api_client.retry_args(types.HttpRetryOptions())
assert args['retry'].predicate(auth_exceptions.TransportError('refresh failed'))
assert not args['retry'].predicate(auth_exceptions.RefreshError('invalid credentials'))


def _patch_auth_default():
return mock.patch(
'google.auth.default',
Expand Down