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

Empty query params in httpx 0.23.1 #222

Closed
g-as opened this issue Nov 18, 2022 · 9 comments
Closed

Empty query params in httpx 0.23.1 #222

g-as opened this issue Nov 18, 2022 · 9 comments

Comments

@g-as
Copy link

g-as commented Nov 18, 2022

encode/httpx#2354

Empty query param is now kept:

def test_empty_query_params():
    q = httpx.QueryParams({"a": ""})
    assert str(q) == "a="

    q = httpx.QueryParams("a=")
    assert str(q) == "a="

    q = httpx.QueryParams("a")
    assert str(q) == "a="

which breaks at least one test:

@pytest.mark.parametrize(
    ("lookup", "params", "url", "expected"),
    [
        ...
        (Lookup.CONTAINS, "x=", "https://foo.bar/?x=1", True),  # query, not params
        ...
    ],
)
def test_params_pattern(lookup, params, url, expected):
    request = httpx.Request("GET", url)
    assert bool(Params(params, lookup=lookup).match(request)) is expected
@lundberg
Copy link
Owner

Spot on again! 😉

@lundberg
Copy link
Owner

lundberg commented Nov 18, 2022

Not sure if we should keep that test, i.e. keep support and allow matching ?x=1 contains ?x= 🤔 ?

We already have the support for ANY when using params map, e.g. params={"x": ANY}.

Maybe better to be strict now that HTTPX keeps empty value params.

@g-as
Copy link
Author

g-as commented Nov 18, 2022

Agreed.

Either drop the test case, or set the expected result to False.

(I edited my initial comment with the actual value from the code (True), since I copied my modifs where I changed it to False)

@g-as
Copy link
Author

g-as commented Nov 18, 2022

But dropping it ensures tests pass for all httpx versions if you don't want to add a version constraint on httpx.

@lundberg
Copy link
Owner

lundberg commented Nov 18, 2022

Either drop the test case, or set the expected result to False.

Yeah, I'd say flipping the expected test result to False is best.

But dropping it ensures tests pass for all httpx versions if you don't want to add a version constraint on httpx.

I think it's fine leaving it even though the test suite breaks on this particular test-case on an old httpx version, I mean that specific contains-match is an undocumented feature so I don't think we need to require httpx 0.23.1 for this fix.

@lundberg
Copy link
Owner

Fixed by #223

@g-as
Copy link
Author

g-as commented Nov 18, 2022

Thanks!

@lundberg
Copy link
Owner

Thanks! ... now released in 0.20.1 🎉

@g-as
Copy link
Author

g-as commented Nov 19, 2022

All good!

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

2 participants