Repository navigation
__contains__ fails for Cookies instance with a duplicate key
#3039
Replies: 1 comment
|
The distinction is existence versus selecting a single value. On HTTPX 0.28.1, the ambiguous-name membership check still raises CookieConflict. You can test existence directly through the public cookie jar without relying on Mapping.contains: import httpx
cookies = httpx.Cookies()
cookies.set("name", "value")
cookies.set("name", "value2", domain="example.com")
exists = any(cookie.name == "name" for cookie in cookies.jar)
assert exists
assert cookies.get("name", domain="example.com", path="/") == "value2"
assert not any(cookie.name == "missing" for cookie in cookies.jar)For selecting a value, specify domain and path. That selection is different from deciding which cookies an actual request should send; let CookieJar apply the request-domain/path policy for that. An existence implementation based on Validated the original exception and the scoped lookup/existence checks above. Cookies API. Validation version: HTTPX 0.28.1, Python 3.11.9. |
Uh oh!
There was an error while loading. Please reload this page.
Hey there,
I've encountered the following issue:
name in cookieswill fail with aCookieConflictwhen aCookieinstance contains multiple cookies with the same name (but different domains/paths). Code to reproduce:I've tracked the issue to the fact that
Cookiesdoes not implement__contains__, but it defers to its parentMapping.__contains__. This in turn will trigger a call toCookies.get(name)and hit the following code path:My hunch is that we should get a
Trueinstead since such a cookie exists in the jar.Do you think it's correct to have a
__contains__defined onCookie, like the one below?All reactions