Repository navigation
Preserve source addresses when pickling adapters - #415
Open
Rajatendu1 wants to merge 1 commit into
Open
Rajatendu1 wants to merge 1 commit into
Rajatendu1 wants to merge 1 commit into
Conversation
Requests restores pool managers using serialized adapter attributes. Include the source address so adapter and Session round-trips retain their binding configuration. Follow the existing SSLAdapter pattern and add direct, proxy and loopback regression coverage. Pick up the fix from the closed, unmerged PR requests#395, whose author explicitly invited others to continue it. Closes requests#394
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #394.
SourceAddressAdapterneeds to includesource_addressin the attributes saved byHTTPAdapter.__getstate__. Without it, restoring a pickled adapter or Session raisesAttributeErrorwhen Requests recreates the pool manager.Use the same
__attrs__extension already used bySSLAdapterandFingerprintAdapter.This picks up the fix proposed in #395, which gyanu2507 closed unmerged after narrowing their projects and explicitly invited others to pick up. Credit to that contribution for the existing diagnosis and fix. This PR adds broader regression coverage rather than claiming a new discovery.
Tests cover string and tuple source addresses (including a nonzero port), pickle protocols 0 and 2, adapters and Sessions, shared HTTP/HTTPS mounts, retained retry/pool settings, rebuilt pool managers and proxy source addresses. Two additional tests make a real loopback HTTP request through an unpickled Session.
Validation on Linux:
python -m pytest -W error::DeprecationWarning, 176 passed, 5 skipped. Requests 2.34.2, urllib3 2.8.0, pyOpenSSL 24.2.1, cryptography 43.0.3. Unchanged baseline: 166 passed, 5 skipped.source_addresserror and pass with the patch.No Windows/macOS or complete interpreter matrix run is claimed. No TLS-policy change is included.
AI assistance was used for investigation, implementation and testing.