Skip to content

HTTPX: type mismatch in values passed to the request/response hooks #2899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
burritoatspoton opened this issue Oct 11, 2024 · 1 comment · Fixed by #3105
Closed

HTTPX: type mismatch in values passed to the request/response hooks #2899

burritoatspoton opened this issue Oct 11, 2024 · 1 comment · Fixed by #3105
Labels
bug Something isn't working

Comments

@burritoatspoton
Copy link

burritoatspoton commented Oct 11, 2024

Describe your environment

OS: MacOS 14.5
Python version: 3.12.7
Package version: 0.48.b0

What happened?

When instrumenting httpx clients e.g. via HTTPXClientInstrumentor.instrument_client, users can pass request_hook and response_hook callables which accept namedtuples RequestInfo/ResponseInfo (type definitions). These tuples contain a header field typed as Optional[List[Tuple[bytes, bytes]]]. However, at runtime this field seems to be copied verbatim from request.headers/response.headers, making it an instance of httpx.Headers. The same applies to a url field in RequestInfo (tuple of values vs httpx.URL). Should the typehints be updated?

Steps to Reproduce

def request_hook(span, request_info):
    print(f"{type(request_info.headers)=} {type(request_info.url)=}")

with httpx.Client() as client:
    HTTPXClientInstrumentor.instrument_client(client, request_hook=request_hook)
    client.get("https://example.com")

Expected Result

type(request_info.headers)=<class 'list'> type(request_info.url)=<class 'tuple'>

Actual Result

type(request_info.headers)=<class 'httpx.Headers'> type(request_info.url)=<class 'httpx.URL'>

Additional context

No response

Would you like to implement a fix?

None

@Kludex
Copy link
Contributor

Kludex commented Dec 13, 2024

I've created the PR above to handle this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants