Skip to content
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

Fix tests for urllib3 v2.0.1+ #1822

Merged
merged 3 commits into from
May 2, 2023
Merged

Fix tests for urllib3 v2.0.1+ #1822

merged 3 commits into from
May 2, 2023

Conversation

basepi
Copy link
Contributor

@basepi basepi commented May 1, 2023

What does this pull request do?

urllib3 v2.0+ introduced a change to args ordering that broke some tests. This fixes those tests (plus a stack frame test that was failing under a new version of VSCode's python extension).

The hangs that were breaking test runs for urllib3 v2.0.0 were due to a regression that has been fixed in v2.0.1. Big thanks to @pquentin, @sethmlarson, and @graingert for help with this!

Related issues

Closes #1816

Comment on lines +64 to +69
from urllib3._version import __version__ as urllib3_version

if urllib3_version.startswith("2") and len(args) >= 5 and args[4]:
headers = args[4].copy()
args = tuple(itertools.chain((args[:4]), (headers,), args[5:]))
elif len(args) >= 4 and args[3]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was initially surprised to see version dependent code here since urllib3 2.0 is supposed to be mostly compatible with urllib3 1.26. Looking more closely, I understand now that you need to set trace headers irrelevant of the way they were set by the caller (arg, kwarg, instance parameter). Since urllib3 2.0 added a body field, it moved headers from 4th positional parameter to 5th positional parameter, and you have to detect this. cc @sethmlarson

Is my understanding right? Should you update the docstring to mention urllib3 2.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you understood correctly. I probably should throw a comment in there for better documentation.

Copy link
Contributor

@beniwohli beniwohli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

urllib3 v2.0 compatibility
3 participants