Skip to content

fix(python): let the httpx client's own timeout apply when a call sets none - #25537

Open
retrry wants to merge 1 commit into
OpenAPITools:masterfrom
retrry:python-httpx-client-default-timeout
Open

retrry wants to merge 1 commit into
OpenAPITools:masterfrom
retrry:python-httpx-client-default-timeout

Conversation

@retrry

@retrry retrry commented Nov 3, 2026 •

Copy link
Copy Markdown

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_timeout uses {{httpxModule}}.USE_CLIENT_DEFAULT, so the client's own timeout applies.
  • _create_pool_manager builds its AsyncClient with timeout=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:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    Regenerated with ./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_timeout now send httpx.USE_CLIENT_DEFAULT so 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.py changed. The aiohttp template is unchanged.

Written for commit e322f84. Summary will update on new commits.

View guided diff

…s none

RESTClientObject.request sent `timeout=_request_timeout or 5 * 60` on every
request. A per-request timeout replaces the client's, so a client set as
pool_manager with its own timeout still waited up to 5 minutes. A call without
_request_timeout now uses the client's timeout, and the client from
_create_pool_manager keeps the 5 minute default.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 7 files

Reply to a comment to ask cubic a question or push back. It learns from your replies.

View guided diff | Re-trigger cubic

@wing328

wing328 commented Nov 3, 2026

Copy link
Copy Markdown
Member

thanks for the PR

cc @cbornet (2017/09) @tomplus (2018/10) @krjakbrjak (2023/02) @fa0311 (2023/10)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants