Skip to content

Commit eac75f3

Browse files
[async] test fixes
1 parent e453042 commit eac75f3

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/snowflake/connector/aio/_session_manager.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -585,17 +585,24 @@ def make_session(self, *, url: str | None = None) -> aiohttp.ClientSession:
585585
session_manager=self.clone(),
586586
snowflake_ocsp_mode=self._cfg.snowflake_ocsp_mode,
587587
)
588-
# We use requests.utils here (in asynch code) to keep the behaviour uniform for synch and asynch code. If we wanted each version to depict its http library's behaviour, we could use here: aiohttp.helpers.proxy_bypass(url, proxies={...}) here
589-
proxy = (
590-
None
591-
if should_bypass_proxies(url, no_proxy=self.config.no_proxy)
592-
else self.proxy_url
593-
)
588+
589+
proxy_from_conn_params: str | None = None
590+
if not aiohttp.helpers.proxies_from_env():
591+
# TODO: This is only needed because we want to keep compatibility with the synch driver version.
592+
# Otherwise, we could remove that condition and always pass proxy from conn params to the Session constructor.
593+
# But in such case precedence will be reverted and it will overwrite the env vars settings.
594+
595+
# We use requests.utils here (in asynch code) to keep the behaviour uniform for synch and asynch code. If we wanted each version to depict its http library's behaviour, we could use here: aiohttp.helpers.proxy_bypass(url, proxies={...}) here
596+
proxy_from_conn_params = (
597+
None
598+
if should_bypass_proxies(url, no_proxy=self.config.no_proxy)
599+
else self.proxy_url
600+
)
594601
# Construct session with base proxy set, request() may override per-URL when bypassing
595602
return self.SessionWithProxy(
596603
connector=connector,
597604
trust_env=self._cfg.trust_env,
598-
proxy=proxy,
605+
proxy=proxy_from_conn_params,
599606
)
600607

601608

test/unit/aio/test_proxies_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,10 +679,10 @@ async def test_proxy_env_vars_take_precedence_over_connection_params(
679679
flags = await _collect_proxy_precedence_flags(
680680
proxy_from_conn_params, proxy_from_env_vars, target_wm
681681
)
682-
assert (
682+
assert not (
683683
flags.proxy1_saw_request
684684
), "proxy_from_conn_params (connection param proxy) should NOT have seen the query request"
685-
assert not flags.proxy2_saw_request, (
685+
assert flags.proxy2_saw_request, (
686686
"proxy_from_env_vars (env var proxy) should have seen the request "
687687
"since connection params take precedence"
688688
)

0 commit comments

Comments
 (0)