Repository navigation
Conversation
CompatErrorHook wrapped httpx errors before the retry loop checked them.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
chrikrah
left a comment
There was a problem hiding this comment.
@fcakyon from my perspective this can be merged. Each new test fails when I put back its half of the change.
# git archive 8fc7787 (base 92f72b3), google.genai.__file__ = <tree>/google/genai/__init__.py, Python 3.12
$ python -m pytest google/genai/tests/interactions/test_httpx_compat.py -q -p no:cacheprovider
8 passed, 14 skipped # head 8fc7787
2 failed, 6 passed, 14 skipped # compat_errors.py from 92f72b3
FAILED ...::test_interactions_retries_connection_errors
FAILED ...::test_async_interactions_retries_connection_errors
1 failed, 7 passed, 14 skipped # google_genai.py from 92f72b3
FAILED ...::test_environment_file_upload_wraps_connection_errors
# default Client (no retry_options), MockTransport raising httpx.ReadTimeout on interactions.create
head 8fc7787: 4 x POST, APITimeoutError
base 92f72b3: 1 x POST, APITimeoutError
# not run: the 14 httpx2 cases, a live endpoint
non-blocking: base already sets retry_connection_errors=True and retries 408 and 5XX on create, so this makes the timeout half of that config take effect, and a timed-out create now goes out four times. Whether a default client retries a non-idempotent POST is for the API owners, not this PR. Would you add the ReadTimeout probe as a test, so that call has the count in front of it?
|
thanks @chrikrah, added the default ReadTimeout case asserting four POST attempts and APITimeoutError |
Fixes #3204.
client.interactionsnever retrieshttpx.ConnectErroror other transport failures, even though_translate_retry_configsetsretry_connection_errors=True.CompatErrorHook.after_errorruns inside the per-attemptdo()inBaseSDK.do_requestand turns the httpx error intoAPIConnectionError._is_transport_errorin the generatedretries.pydoes not recognize that type, so the retry loop raises it as aPermanentErroron the first attempt.after_errornow returns errors unchanged. Translation happens once, at the public boundary, inwrap_sdk_call/async_wrap_sdk_call, which the bridge methods already call (raw and streaming responses go through_RawResponseAccessorProxy). Callers still getAPIConnectionError/APITimeoutErrorwith the httpx error as__cause__.environments.files.uploadwas the one bridge path that called generated code (self._internal.start_upload, sync and async) withoutwrap_sdk_call. It is wrapped now, so it keeps raisingAPIConnectionError.basesdk.pyandretries.pyare Speakeasy output.HttpRetryOptions(attempts=3)and a transport that always raisesConnectError: 1 attempt before, 4 after, the same as a 503. Sync, async, and the httpx2 client all behave this way._translate_retry_configdefaults to 3 retries whenretry_optionsis unset, so default clients now retry connection errors and timeouts (httpx.TimeoutException) too. Themodelspath already retries these whenHttpRetryOptionsis set (fix(retry): retry on httpx.TimeoutException with HttpRetryOptions #2345, fix: Honor HttpRetryOptions for aiohttp connection errors in async requests #3186).test_httpx_compat.py: the sync and async interactions tests fail onmain(assert 1 > 1), and the upload test fails without the newwrap_sdk_call(rawhttpx.ConnectError).