Skip to content

Saved cookiejars with partitioned cookies are unable to be loaded in python <= 3.13 #11523

@Cycloctane

Description

@Cycloctane

Describe the bug

aiohttp use __setitem__ to make cookie's partitioned attribute available in python <= 3.13 (#11112 ):

if lower_key == "partitioned" and sys.version_info < (3, 14):
dict.__setitem__(current_morsel, lower_key, True)

This actually makes pickled cookies contain attribute not supported in standard http.cookie. Pickled cookiejars are not able to be unpickled if they contain partitioned cookies.

To Reproduce

from aiohttp import CookieJar

cj = CookieJar()
cj.update_cookies_from_headers(["a=a; Partitioned"], response_url=URL("http://example.com/"))
cj.save("cookies.bin")
CookieJar().load("cookies.bin")
File "D:\Program Files\Python311\Lib\site-packages\aiohttp\cookiejar.py", line 133, in load
    self._cookies = pickle.load(f)
                    ^^^^^^^^^^^^^^
  File "D:\Program Files\Python311\Lib\http\cookies.py", line 312, in __setitem__
    raise CookieError("Invalid attribute %r" % (K,))
http.cookies.CookieError: Invalid attribute 'partitioned'

Python Version

<=3.13

aiohttp Version

>=3.12.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions