fix: user-configured proxies being overridden by http_proxy/https_proxy env vars - #2445
Open
cristianchiriac wants to merge 2 commits into
Open
cristianchiriac wants to merge 2 commits into
cristianchiriac wants to merge 2 commits into
Conversation
… vars ResilientSession.request() never forwarded a "proxies" kwarg to requests.Session.request(), relying entirely on self.proxies as the fallback. But requests.Session.merge_environment_settings() only uses self.proxies as a fallback for keys missing from the per-request proxies dict; when no "proxies" kwarg is passed, that dict starts empty and gets filled first from the http_proxy/https_proxy environment variables via setdefault(), before merge_setting() lets those request-level values win over self.proxies for any matching key. The end result: a JIRA client configured with an explicit proxies dict silently used the environment's proxies instead whenever those env vars were also set. Pass self.proxies through explicitly as the "proxies" kwarg in _jira_prepare() so it's already populated before the environment fallback runs, and can only fill gaps rather than being overridden. Fixes pycontribs#2398
for more information, see https://pre-commit.ci
|
Label error. Requires at least 1 of: breaking, chore, feat, fix. Found: . Follow https://www.conventionalcommits.org to get auto-labeling to work correctly. |
This branch has not been deployed
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 #2398.
Bug
JIRA(..., proxies={...})setsself._session.proxieson theResilientSession, butResilientSession.request()never forwards aproxieskwarg torequests.Session.request()— it relies onself.proxiesbeing picked up as a fallback. That fallback only works for keys that are still missing by the timerequestsdoes its final merge.Tracing through
requests.Session.request():proxies = proxies or {}— since noproxieskwarg was passed, this starts as an empty dict.merge_environment_settings(url, proxies, ...)fills that empty dict from thehttp_proxy/https_proxyenvironment variables viaproxies.setdefault(k, v), then callsproxies = merge_setting(proxies, self.proxies).merge_setting(request_setting, session_setting)builds the result by copyingsession_setting(self.proxies, the configured value) first, then calling.update(request_setting)— so the request-level dict (now populated from the environment) overwritesself.proxiesfor any matching key.Net effect: whenever
http_proxy/https_proxyare set in the environment, they silently win over an explicitly configuredproxiesdict, even though the explicit configuration should be authoritative.I confirmed this against the actual
requestsmerge functions:Fix
_jira_prepare()now passesself.proxiesthrough explicitly as theproxieskwarg (when set and not already overridden per-call), so it's already populated beforemerge_environment_settings()'s environment fallback runs —setdefault()then only fills genuinely missing keys instead of a dict that later overwrites the configured values.Test plan
test_configured_proxies_are_forwarded, verifying a session-levelproxiesdict is passed through torequests.Session.request()unchanged.test_no_proxies_kwarg_when_unconfigured, verifying noproxieskwarg is added when none was configured (preserving prior behavior/defaults for the common case).pytest tests/test_resilientsession.py: 37 passed.ruff checkandruff format --checkon the changed files: clean.