Skip to content

Regression in urllib.parse.parse_qsl(None) behavior #116764

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

Closed
msullivan opened this issue Mar 13, 2024 · 3 comments
Closed

Regression in urllib.parse.parse_qsl(None) behavior #116764

msullivan opened this issue Mar 13, 2024 · 3 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@msullivan
Copy link
Contributor

msullivan commented Mar 13, 2024

Bug report

Bug description:

#115771 introduced a change in some currently working behavior. Previously:

import urllib.parse
>>> urllib.parse.parse_qsl(None)
[]

but now it raises TypeError: cannot convert 'NoneType' object to bytes.

(parse_qs also broke, since it calls parse_qsl)

I think it's obviously pretty debatable whether the old behavior was desirable but there is popular code in the wild that depends on it: https://github.com/encode/httpx/blob/7df47ce4d93a06f2c3310cd692b4c2336d7663ba/httpx/_urls.py#L431-L433.

(I stumbled across this when one of my colleagues was accidentally using a current dev branch of 3.11 and started getting mysterious errors from inside the bowels of the httpx client.)

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

@msullivan msullivan added the type-bug An unexpected behavior, bug, or error label Mar 13, 2024
@msullivan
Copy link
Contributor Author

@serhiy-storchaka If there's agreement that the old behavior when passing None should be preserved, I can submit a patch.

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Mar 14, 2024
* Restore support of None and other false values (fix regression
  introduced in pythongh-74668).
* Raise TypeError for non-zero integers and non-empty sequences.
@serhiy-storchaka
Copy link
Member

Thank you for your report @msullivan. This looks as a serious reason to restore support of false values, even if it was not intentional behavior.

I already started to write a PR when I requested for creating this issue. The fix was trivial, but there was substantial lack of tests, and new tests exposed other flaws in this code, so the final code is more complicated.

serhiy-storchaka added a commit that referenced this issue Mar 16, 2024
* Restore support of None and other false values.
* Raise TypeError for non-zero integers and non-empty sequences.

The regressions were introduced in gh-74668
(bdba8ef).
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 16, 2024
…H-116801)

* Restore support of None and other false values.
* Raise TypeError for non-zero integers and non-empty sequences.

The regressions were introduced in pythongh-74668
(bdba8ef).
(cherry picked from commit 1069a46)

Co-authored-by: Serhiy Storchaka <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 16, 2024
…H-116801)

* Restore support of None and other false values.
* Raise TypeError for non-zero integers and non-empty sequences.

The regressions were introduced in pythongh-74668
(bdba8ef).
(cherry picked from commit 1069a46)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit that referenced this issue Mar 16, 2024
) (GH-116894)

* Restore support of None and other false values.
* Raise TypeError for non-zero integers and non-empty sequences.

The regressions were introduced in gh-74668
(bdba8ef).
(cherry picked from commit 1069a46)

Co-authored-by: Serhiy Storchaka <[email protected]>
@serhiy-storchaka
Copy link
Member

Opened #116897 for deprecating support of generic false values.

serhiy-storchaka added a commit that referenced this issue Mar 16, 2024
) (GH-116895)

* Restore support of None and other false values.
* Raise TypeError for non-zero integers and non-empty sequences.

The regressions were introduced in gh-74668
(bdba8ef).
(cherry picked from commit 1069a46)

Co-authored-by: Serhiy Storchaka <[email protected]>
vstinner pushed a commit to vstinner/cpython that referenced this issue Mar 20, 2024
…H-116801)

* Restore support of None and other false values.
* Raise TypeError for non-zero integers and non-empty sequences.

The regressions were introduced in pythongh-74668
(bdba8ef).
adorilson pushed a commit to adorilson/cpython that referenced this issue Mar 25, 2024
…H-116801)

* Restore support of None and other false values.
* Raise TypeError for non-zero integers and non-empty sequences.

The regressions were introduced in pythongh-74668
(bdba8ef).
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
…H-116801)

* Restore support of None and other false values.
* Raise TypeError for non-zero integers and non-empty sequences.

The regressions were introduced in pythongh-74668
(bdba8ef).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants