Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@Ajay9704
Copy link

Summary

This PR fixes an issue where custom CookiePolicy objects set on a session’s cookie jar were being lost during request preparation.

The Problem

When requests.Session.prepare_request() merged cookies, it created a new RequestsCookieJar without copying over the policy from the session jar. As a result, custom policies (like allowing secure cookies on localhost) worked when storing cookies, but not when preparing requests to send them.

The Fix

The merge logic in prepare_request() now preserves the existing policy by applying the session jar’s policy to the new jar before merging. This ensures policy decisions are still consulted during request preparation.

Impact

This resolves long-standing issue #7122 and restores the ability to rely on custom cookie policy behavior without breaking existing functionality. The change is contained, minimal, and only affects scenarios where a custom policy is explicitly set.

When merging cookies in Session.prepare_request, custom cookie policies
set on the session's cookie jar were being lost. This fix preserves
the policy by copying it to the new RequestsCookieJar during merging.

Fixes psf#7122
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.