Skip to content
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

Breaking Change in httpx 0.28.1: Handling of Empty params in URL #3483

Closed
to-bee opened this issue Jan 25, 2025 · 2 comments
Closed

Breaking Change in httpx 0.28.1: Handling of Empty params in URL #3483

to-bee opened this issue Jan 25, 2025 · 2 comments

Comments

@to-bee
Copy link

to-bee commented Jan 25, 2025

Issue Description

After upgrading httpx from version 0.27.2 to 0.28.1, tests using the FastAPI test client are failing due to changes in how the URL object handles params during construction.

The issue was traced to the following code:

Version 0.27.2:

self.url = URL(url)
if params is not None:
    self.url = self.url.copy_merge_params(params=params)

Version 0.28.1:

self.url = URL(url) if params is None else URL(url, params=params)

In httpx 0.28.1, passing params=None or params=[] to the URL constructor causes query parameters to be removed from the URL.

@YuriiMotov
Copy link

YuriiMotov commented Jan 26, 2025

Here is a MRE:

from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route
from starlette.testclient import TestClient


async def get_index(request):
    query_params = request.query_params
    a = query_params.get("a")
    b = query_params.get("b")
    b = b.lower() == "true" if b is not None else None
    return JSONResponse({"a": a, "b": b})


app = Starlette(routes=[Route("/index", get_index)])


def test_():
    client = TestClient(app)
    resp = client.get("/index?a=123", params={})
    assert resp.status_code == 200
    resp_json = resp.json()
    assert resp_json["a"] == "123"
    assert resp_json["b"] is None

The test above fails after you upgrade to httpx 0.28.1

@Kludex
Copy link
Member

Kludex commented Jan 26, 2025

Duplicated of #3433

@Kludex Kludex closed this as not planned Won't fix, can't repro, duplicate, stale Jan 26, 2025
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

No branches or pull requests

3 participants