Repository navigation
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
Description
With library=httpx, the generated Configuration documents and accepts a retries option
(:param retries: int - Retry configuration.), but rest.py never reads it:
_create_pool_manager() builds an httpx.AsyncClient without any retry setting.
The value is silently dropped.
The other libraries do honor it:
| library | Configuration.retries used by rest.py |
|---|---|
| urllib3 | yes (PoolManager(retries=...)) |
| asyncio | yes (aiohttp_retry) |
| httpx | no |
Consequence: clients migrating from urllib3 to httpx silently lose their connect retries.
openapi-generator version
7.25.0, still present on master (f885a67).
OpenAPI declaration file content or url
Any spec, e.g. modules/openapi-generator/src/test/resources/3_0/petstore.yaml.
Generation Details
bin/configs/python-httpx.yaml (same template for python-httpx-sync, python-httpx2, python-httpx2-sync).
Steps to reproduce
Using the samples/openapi3/client/petstore/python-httpx sample from master, with nothing listening on the target port:
import asyncio
import petstore_api
cfg = petstore_api.Configuration(host="http://127.0.0.1:1", retries=3)
async def main():
async with petstore_api.ApiClient(cfg) as c:
await petstore_api.PetApi(c).get_pet_by_id(1)
asyncio.run(main())Expected: 4 connection attempts (1 + 3 retries), then httpx.ConnectError.
Actual: 1 connection attempt, then httpx.ConnectError. The underlying httpcore.AsyncConnectionPool is created with retries=0.
For comparison, httpx.AsyncClient(transport=httpx.AsyncHTTPTransport(retries=3)) makes 4 attempts against the same address.
Related issues/PRs
- [python] add async httpx support #22021 (httpx support), [python] add supportHttpxSync option for sync httpx methods #24128 (
supportHttpxSync), [Python] Add HTTPX2 client library support #24966 (httpx2) - Open PRs touching the same template: fix(python): let the httpx client's own timeout apply when a call sets none #25537, [python] honor assert_hostname in the asyncio and httpx clients #25796
Suggest a fix
Pass retries to httpx.AsyncHTTPTransport(retries=...). httpx only retries
ConnectError/ConnectTimeout (the request was never sent), so it is safe for every HTTP method.
Caveat: passing a custom transport to AsyncClient disables environment proxies
(allow_env_proxies = trust_env and transport is None), and an explicit proxy= on the client
mounts its own transport that bypasses the custom one. So the transport should only be built when
retries is set, with the explicit proxy passed to the transport rather than to the client.
PR #25820
Activity