Skip to content

Add support for httpx authentication class - #2953

Open
vruello wants to merge 1 commit into
elastic:mainfrom
vruello:httpx_auth
Open

Add support for httpx authentication class#2953
vruello wants to merge 1 commit into
elastic:mainfrom
vruello:httpx_auth

Conversation

@vruello

@vruello vruello commented Apr 30, 2025

Copy link
Copy Markdown

This PR adds support for passing a custom authentication class to the httpx client (#2933) with minimal changes. It is heavily inspired by the existing implementation for the requests client. Internally, it uses the already existing requests_session_auth parameter.

See the corresponding PR in elasticsearch-py : elastic/elastic-transport-python#244

@margaretjgu

Copy link
Copy Markdown
Member

/ai-review

@github-actions

Copy link
Copy Markdown

The code looks mostly correct. A few issues to flag:

Bug: Wrong variable used for httpx auth

In _async/client/__init__.py, the httpx auth block reuses requests_session_auth:

requests_session_auth = http_auth  # <-- wrong variable name
http_auth = DEFAULT

This mirrors the requests pattern but the variable name is semantically wrong. More critically, look at what happens downstream: if requests_session_auth was already set by the requests block above, this overwrites it. And if the consuming code only checks requests_session_auth to pass it to requests-specific node config, the httpx auth value may be silently ignored or misrouted. There should be a separate httpx_session_auth variable (or equivalent) that gets passed to the httpx node config path.

Unused import

In _async/client/utils.py:

from typing import (
    TYPE_CHECKING,
    Any,
)

TYPE_CHECKING is imported but never used.

elastic_transport import may not be available

from elastic_transport import HttpxAsyncHttpNode

If httpx is not installed, HttpxAsyncHttpNode may not be importable from elastic_transport (depending on how elastic_transport handles optional dependencies). This could cause an ImportError at module import time rather than at call time. The is_httpx_http_auth function correctly wraps its import in a try/except, but is_httpx_node_class does not — it imports HttpxAsyncHttpNode unconditionally at module level.

is_httpx_node_class logic gap

The string "httpxasync" is hardcoded. If elastic_transport ever changes the alias, this silently breaks. Minor, but worth a comment referencing where that string is defined.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants