Skip to content

CookieJar filter_cookies does not preserve expiration date #3951

@bwright1558

Description

@bwright1558

Long story short

Using CookieJar.filter_cookies() does not preserve the expiration date of the returned cookies.

Expected behaviour

Return the full cookie Morsels that have the expires, domain, path, etc. fields.

Actual behaviour

The expires field is not included in the cookie Morsels returned from CookieJar.filter_cookies().

Steps to reproduce

Here's a full working example to demonstrate. It's a contrived example, but it gets the point across. Iterating through cookie_jar gives me the full Morsel objects with expiration. But iterating through filtered_cookies does not contain the expiration.

from http.cookies import SimpleCookie

import yarl
from aiohttp import CookieJar


cookies = SimpleCookie()
cookies.load('browser_session=secret; Domain=.test.com; Path=/; Expires=Tue, 30-Jul-69 14:47:41 GMT; HttpOnly')

cookie_jar = CookieJar()
cookie_jar.update_cookies(cookies)

for cookie in cookie_jar:
    print(f'{cookie.value!r} expires {cookie["expires"]!r}')

url = yarl.URL('http://www.test.com')
filtered_cookies = cookie_jar.filter_cookies(url)
for _, cookie in filtered_cookies.items():
    print(f'{cookie.value!r} expires {cookie["expires"]!r}')

Your environment

I'm using the latest stable release of aiohttp (3.5.4).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions