Skip to content

[python] honor assert_hostname in the asyncio and httpx clients - #25796

Open
Yohan-Senadheera wants to merge 1 commit into
OpenAPITools:masterfrom
Yohan-Senadheera:python-assert-hostname
Open

Yohan-Senadheera wants to merge 1 commit into
OpenAPITools:masterfrom
Yohan-Senadheera:python-assert-hostname

Conversation

@Yohan-Senadheera

@Yohan-Senadheera Yohan-Senadheera commented Nov 23, 2026 •

Copy link
Copy Markdown

The urllib3 client passes Configuration.assert_hostname to the pool manager, but the asyncio (aiohttp) and httpx clients never read it, so assert_hostname=False has no effect there.

This sets ssl_context.check_hostname from it when verify_ssl is on. With verify_ssl off it is left alone, so certificate verification is not switched back on.

Context: the Kubernetes Python client hit this in its asyncio client (kubernetes-client/python#2795). The maintainers asked for the fix here in the generator rather than as a post-processing patch (kubernetes-client/gen#314).

Changes:

  • python/asyncio/rest.mustache and python/httpx/rest.mustache
  • regenerated rest.py in the python-aiohttp, python-httpx, python-httpx-sync, python-httpx2 and python-httpx2-sync samples
  • tests in the python-aiohttp and python-httpx samples (TestAssertHostname): they fail on master and pass with this change. The rest of each sample suite is unchanged (the pet API tests need a running petstore server).

PR checklist

  • Read the contribution guidelines.
  • Updated samples: regenerated the five affected samples with openapi-generator-cli 7.27.0 and the changed templates (batch bin/configs/<config>.yaml); the generated rest.py files match the committed ones exactly. Only rest.mustache changed, so no other generated file is affected.
  • @mention the technical committee: @cbornet @tomplus @krjakbrjak @fa0311 @AndreyVMarkelov

Summary by cubic

Honors assert_hostname in the asyncio (aiohttp) and httpx clients so assert_hostname=False disables hostname checks there, matching the urllib3 client. This fixes the Kubernetes Python client's asyncio client (kubernetes-client/python#2795). Hostname checking is only applied when verify_ssl is on, so disabling verification never re-enables it.

  • Added tests in the aiohttp and httpx samples covering both cases.

Written for commit 2d4776a. Summary will update on new commits.

View guided diff

The urllib3 client passes Configuration.assert_hostname to the pool
manager, but the asyncio (aiohttp) and httpx clients never read it, so
assert_hostname=False has no effect there.

Set ssl_context.check_hostname from it when verify_ssl is on. With
verify_ssl off it is left alone, so certificate verification is not
switched back on.

Signed-off-by: Yohan Senadheera <yohansenadheera@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 04:39

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@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.

No issues found across 9 files

View guided diff | Re-trigger cubic

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