Skip to content

httpx 0.25.0 changes decoding behaviour of .query_params when using TestClient #2282

@Kludex

Description

@Kludex

Discussed in #2281

Originally posted by chris48s September 13, 2023
Hello. I'm not really sure if this is an issue with starlette or httpx. It kind of sits at the intersection between the two. Here''s a minimal example application:

app.py:

from starlette.applications import Starlette
from starlette.responses import Response
from starlette.routing import Route

async def index(request):
    foo = request.query_params.get("foo")
    return Response(foo, status_code=200, media_type="text/html")

routes = [Route("/", endpoint=index)]

app = Starlette(debug=True, routes=routes)

..and here's a unit test (pytest):

test.py:

from starlette.testclient import TestClient

from app import app

def test_foo():
    client = TestClient(app)
    response = client.get("/?foo=%3A/")
    assert ":/" == response.text

If I run that test with

starlette==0.31.1
httpx==0.24.1

installed, the test passes.


Install

starlette==0.31.1
httpx==0.25.0

and run it again. The test now fails. The output is %3A/ not :/


Note that the actual application behaviour is unchanged. i.e: when invoked independently of TestClient (I'm serving with uvicorn app:app), the response is still :/ in either case.

This seems like it could be related to encode/httpx#2844 but I decided to open a discussion specifically about the impact on starlette TestClient

Important

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions