fix(python): let the httpx client's own timeout apply when a call sets none
The httpx and httpx2 rest.py sends timeout=_request_timeout or 5 * 60 on every request. In HTTPX a per-request timeout replaces the client's, so a client set as pool_manager with its own timeout still waits up to 5 minutes unless every call passes _request_timeout. Configuration has no timeout setting, so there is no other way to change it.
This change moves the 5 minute default from the request to the client:
- A call without
_request_timeoutuses{{httpxModule}}.USE_CLIENT_DEFAULT, so the client's own timeout applies. _create_pool_managerbuilds itsAsyncClientwithtimeout=5 * 60, so clients the generator creates keep the current 300 s default.
The urllib3 rest.py already behaves this way: without _request_timeout it leaves the timeout unset and uses the pool manager's. The aiohttp template has the same 5 * 60 line but a different timeout API, so it is left out of this PR.
Validation: regenerated the four httpx samples (python-httpx, python-httpx-sync, python-httpx2, python-httpx2-sync); only rest.py changed. Added two tests to the httpx2 samples' test_httpx2_transport.py: a supplied client's timeout applies when the call sets none, and the generated client defaults to 300 s. Both fail on master and pass with this change. The sample suites pass except test_pet_api.py, which needs a local Petstore server.
PR checklist
- Read the contribution guidelines.
- Run the following to build the project and update samples:
Regenerated with./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit./bin/generate-samples.sh bin/configs/python-httpx*.yaml, the only configs using this template. - If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
Python technical committee: @wing328
Summary by cubic
Fixes the httpx Python templates so calls without _request_timeout honor the pool manager's own timeout instead of always forcing a 5-minute default. The 5-minute default is now set on the generated AsyncClient in _create_pool_manager, so generated clients keep the current 300-second timeout.
- Requests without
_request_timeoutnow sendhttpx.USE_CLIENT_DEFAULTso the client's timeout applies. - Added tests verifying a supplied client's timeout is used and the generated client defaults to 300 seconds.
- Regenerated the four httpx samples; only
rest.pychanged. The aiohttp template is unchanged.