This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: http.cookiejar handle cookie.version to be None
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: alclarks, kovid, xtreak
Priority: normal Keywords: 3.8regression

Created on 2019-11-17 10:34 by kovid, last changed 2022-04-11 14:59 by admin.

Messages (7)
msg356797 - (view) Author: Kovid Goyal (kovid) Date: 2019-11-17 10:34
In python 3.8 cookiejar.py is full of code that compares cookie.version to integers, which raises as exception when cookie.version is None. For example, in set_ok_version() and set_ok_path(). Both the Cookie constructor and _cookie_from_cookie_tuple() explicitly assume version can be None and setting version to None worked fine in previous pythonreleases.
msg356798 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-11-17 10:53
Can you please add a sample script to reproduce this that worked fine before Python 3.8?
msg356802 - (view) Author: Kovid Goyal (kovid) Date: 2019-11-17 12:10
The issue is obvious with a simple glance at the code. Either the Cookie constructor needs to change version = None to zero or some other integer or the various methods in that module need to handle a None version. I dont personally care about this issue any more since I have worked around it in my code, feel free to fix it or not, as you wish.
msg356804 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-11-17 13:02
You specifically mentioned Python 3.8 and I just wanted to understand the issue to see if it's a regression. I don't see any version related code changes in recent times. Hence this is not necessarily a regression in 3.8 unless there is a reproducible script. The code in set_ok_version for cookie.version to be None is not tested hence I assume there are no tests for the reported scenario that would be good to have. I have also changed the issue title accordingly.
msg356805 - (view) Author: Kovid Goyal (kovid) Date: 2019-11-17 13:18
It's trivially True that it is a regression from python 2 since in python 2 comparison to None is fine. Whether it ever worked in any python 3 version before 3.8 I'm not sure about.
msg356807 - (view) Author: Kovid Goyal (kovid) Date: 2019-11-17 13:21
Here's a trivial script to reproduce:

from urllib.request import Request
from http.cookiejar import Cookie, CookieJar

jar = CookieJar()
jar.set_cookie(Cookie(
            None, 'test', 'test',
            None, False,
            '.test.com', True, False,
            '/', True,
            False, None, False, None, None, None
        ))
r = Request('http://www.test.com')
jar.add_cookie_header(r)
msg356960 - (view) Author: Alex (alclarks) * Date: 2019-11-19 10:48
Hi, it looks like this needs a fix - I'll write a patch to fix up the handling and add some more testing to cover this scenario.
History
Date User Action Args
2022-04-11 14:59:23adminsetgithub: 83009
2019-11-19 10:48:27alclarkssetnosy: + alclarks
messages: + msg356960
2019-11-17 13:21:51kovidsetmessages: + msg356807
2019-11-17 13:18:14kovidsetmessages: + msg356805
2019-11-17 13:02:19xtreaksetmessages: + msg356804
title: cookiejar.py broken in 3.8 -> http.cookiejar handle cookie.version to be None
2019-11-17 12:14:14SilentGhostsetkeywords: + 3.8regression
type: crash -> behavior
stage: test needed
2019-11-17 12:10:04kovidsetmessages: + msg356802
2019-11-17 10:53:27xtreaksetnosy: + xtreak
messages: + msg356798
2019-11-17 10:34:51kovidcreate