Repository navigation
Conversation
Configuration.retries is documented for the httpx library but rest.py never read it. Pass it to AsyncHTTPTransport(retries=...): httpx only retries connection failures, so it is safe for every method. The transport is only built when retries is set: a custom transport disables proxies from environment variables, and a client-level proxy would bypass it, so the explicit proxy goes to the transport. Fixes OpenAPITools#25801 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
1 issue found across 14 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/openapi3/client/petstore/python-httpx/petstore_api/rest.py">
<violation number="1" location="samples/openapi3/client/petstore/python-httpx/petstore_api/rest.py:207">
P2: With retries enabled, each connect attempt gets the full timeout, so an unreachable host can block for up to (retries + 1) × timeout plus backoff. That breaks the total-timeout contract documented in `request()`. Document this behavior, or enforce an overall deadline.</violation>
</file>
Reply to a comment to ask cubic a question or push back. It learns from your replies.
View guided diff | Re-trigger cubic
| verify=self.ssl_context, | ||
| limits=limits, | ||
| proxy=proxy, | ||
| retries=self.retries, |
There was a problem hiding this comment.
P2: With retries enabled, each connect attempt gets the full timeout, so an unreachable host can block for up to (retries + 1) × timeout plus backoff. That breaks the total-timeout contract documented in request(). Document this behavior, or enforce an overall deadline.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At samples/openapi3/client/petstore/python-httpx/petstore_api/rest.py, line 207:
<comment>With retries enabled, each connect attempt gets the full timeout, so an unreachable host can block for up to (retries + 1) × timeout plus backoff. That breaks the total-timeout contract documented in `request()`. Document this behavior, or enforce an overall deadline.</comment>
<file context>
@@ -193,6 +195,22 @@ def _create_pool_manager(self) -> httpx.AsyncClient:
+ verify=self.ssl_context,
+ limits=limits,
+ proxy=proxy,
+ retries=self.retries,
+ )
+ return httpx.AsyncClient(
</file context>
- Only build the retry transport for a positive retries count. - Document httpx's limits instead of working around them: proxies from environment variables are ignored with a custom transport, and requests sent through a proxy are not retried (encode/httpx#2997). Each attempt gets the full connect timeout. - Tests count real connection attempts instead of transport kwargs, and cover retries=0 and negative values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
1 issue found across 14 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/openapi3/client/petstore/python-httpx/tests/test_retries.py">
<violation number="1" location="samples/openapi3/client/petstore/python-httpx/tests/test_retries.py:15">
P2: This helper releases the selected port before the request starts, creating a race with other processes that can make the retry-count assertions flaky. Keep the reservation lifecycle through the connection attempt or use a deterministic local failure mechanism.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| def closed_port(): | ||
| with socket.socket() as sock: | ||
| sock.bind(("127.0.0.1", 0)) | ||
| return sock.getsockname()[1] |
There was a problem hiding this comment.
P2: This helper releases the selected port before the request starts, creating a race with other processes that can make the retry-count assertions flaky. Keep the reservation lifecycle through the connection attempt or use a deterministic local failure mechanism.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At samples/openapi3/client/petstore/python-httpx/tests/test_retries.py, line 15:
<comment>This helper releases the selected port before the request starts, creating a race with other processes that can make the retry-count assertions flaky. Keep the reservation lifecycle through the connection attempt or use a deterministic local failure mechanism.</comment>
<file context>
@@ -1,24 +1,57 @@
+def closed_port():
+ with socket.socket() as sock:
+ sock.bind(("127.0.0.1", 0))
+ return sock.getsockname()[1]
+
+
</file context>
httpx does not retry through a proxy (encode/httpx#2997), and a custom transport disables proxies from environment variables. Building the retry transport with a proxy brought no retry and broke environment proxies. Only build it for direct connections: no Configuration.proxy and no proxy from the environment (urllib.request.getproxies, as httpx does). Otherwise the client is built as before, so this change is not breaking. Tests pin that behavior for explicit and environment proxies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
2 issues found across 14 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/openapi3/client/petstore/python-httpx2/tests/test_retries.py">
<violation number="1" location="samples/openapi3/client/petstore/python-httpx2/tests/test_retries.py:48">
P3: These added test lines exceed the repository’s configured 99-character Flake8 limit, so the sample fails lint when Flake8 is run. Wrap the docstring, mock context, assertions, and proxy test context across lines.</violation>
</file>
<file name="samples/openapi3/client/petstore/python-httpx/tests/test_retries.py">
<violation number="1" location="samples/openapi3/client/petstore/python-httpx/tests/test_retries.py:48">
P3: Several added lines exceed this sample’s configured 99-character flake8 limit, causing lint failures when flake8 runs. Wrap the helper, patch, assertion, and context-manager lines to keep each line within the configured limit.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| @@ -0,0 +1,104 @@ | |||
| """Configuration.retries is passed to httpx2's transport retries, for direct connections.""" | |||
There was a problem hiding this comment.
P3: These added test lines exceed the repository’s configured 99-character Flake8 limit, so the sample fails lint when Flake8 is run. Wrap the docstring, mock context, assertions, and proxy test context across lines.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At samples/openapi3/client/petstore/python-httpx2/tests/test_retries.py, line 48:
<comment>These added test lines exceed the repository’s configured 99-character Flake8 limit, so the sample fails lint when Flake8 is run. Wrap the docstring, mock context, assertions, and proxy test context across lines.</comment>
<file context>
@@ -26,13 +37,23 @@ async def counting_connect_tcp(*args, **kwargs):
return len(attempts)
+ def build_client(self, config):
+ """Return the REST client, the transport kwargs (None if no custom transport) and the client kwargs."""
+ rest = RESTClientObject(config)
+ with patch("petstore_api.rest.httpx2.AsyncHTTPTransport", wraps=httpx2.AsyncHTTPTransport) as transport, \
</file context>
| @@ -0,0 +1,104 @@ | |||
| """Configuration.retries is passed to httpx's transport retries, for direct connections.""" | |||
There was a problem hiding this comment.
P3: Several added lines exceed this sample’s configured 99-character flake8 limit, causing lint failures when flake8 runs. Wrap the helper, patch, assertion, and context-manager lines to keep each line within the configured limit.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At samples/openapi3/client/petstore/python-httpx/tests/test_retries.py, line 48:
<comment>Several added lines exceed this sample’s configured 99-character flake8 limit, causing lint failures when flake8 runs. Wrap the helper, patch, assertion, and context-manager lines to keep each line within the configured limit.</comment>
<file context>
@@ -26,13 +37,23 @@ async def counting_connect_tcp(*args, **kwargs):
return len(attempts)
+ def build_client(self, config):
+ """Return the REST client, the transport kwargs (None if no custom transport) and the client kwargs."""
+ rest = RESTClientObject(config)
+ with patch("petstore_api.rest.httpx.AsyncHTTPTransport", wraps=httpx.AsyncHTTPTransport) as transport, \
</file context>
Fixes #25801
Configuration.retriesis documented for the httpx library but ignored byrest.py.This PR passes it to httpx's own retry mechanism,
AsyncHTTPTransport(retries=...),without working around httpx's limits and without breaking existing setups.
Behavior
retriesunset,0or negativeretries > 0, direct connectionretries > 0+Configuration.proxyretries > 0+ proxy from environment (HTTP(S)_PROXY,ALL_PROXY)httpx retries only
ConnectError/ConnectTimeout(the request was never sent), so thisis safe for all HTTP methods, unlike the asyncio client which restricts retries to
ALLOW_RETRY_METHODS.Why retries are limited to direct connections
With a proxy, httpx's transport retries bring nothing and have a side effect:
AsyncHTTPTransportdoes not forwardretriesto
AsyncHTTPProxy/AsyncSOCKSProxy(Fixing missed arguments for pools when init transports encode/httpx#2997, open). Checked with httpx0.28.1 and httpx2 2.16.2:
retries=2gives 3 connection attempts directly, 1 througha proxy.
(
allow_env_proxies = trust_env and transport is None, encode/httpx discussion [BUG] okhttp-gson generation on windows creates a uncompilable build.gradle #2593).Building it would send requests directly instead of through the proxy.
So the retry transport is only built when there is no proxy: no
Configuration.proxyand none from the environment, detected with
urllib.request.getproxies()(what httpxreads as well;
NO_PROXYalone does not count). Otherwise the client is built exactly asbefore. This is documented in the
Configurationdocstring, together with the fact thateach attempt gets the full connect timeout, with httpcore's backoff between attempts
(0 s, 0.5 s, 1 s…).
If encode/httpx#2997 is fixed, the proxy condition can be revisited.
Changes
python/httpx/rest.mustache:_create_pool_manager()buildsAsyncHTTPTransport(retries=..., verify=..., limits=...)whenretries > 0and noproxy is set.
python/configuration.mustache: document whatretriescovers for httpx.python-httpx,python-httpx-sync,python-httpx2,python-httpx2-sync.tests/test_retries.pyin these four samples:retries=2against a closed port: 3 real connection attempts, counted atanyio.connect_tcp;retriesunset,0,-1: 1 attempt, and the client is built as before;retries=3: TLS context and connection limit go to the transport;NO_PROXYalonekeeps the retries;
retries=3withConfiguration.proxy, or withHTTP_PROXY,https_proxyorALL_PROXYin the environment: the client is built as before.Testing
current behavior).
test_pet_api.pyneeds the petstore server, and mypy reports the same error in
signing.py.PR checklist
./mvnw clean package -DskipTests -pl modules/openapi-generator-cli -am, template-only change) and ran./bin/generate-samples.shon the fourbin/configs/python-httpx*.yamlconfigs, committed all changed files. No generator option changed, so the generator docs are unaffected.🤖 Generated with Claude Code