Skip to content

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

@basepi basepi requested a review from beniwohli May 1, 2023 22:13
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
3 participants