Skip to content

Commit d60be94

Browse files
[async] test fixes:
Fixed synch factory in async code of _wif.py Fixed async make_session and added necessary host_port_pooling
1 parent ea94c70 commit d60be94

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/snowflake/connector/aio/_session_manager.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -541,17 +541,24 @@ def make_session(self, *, url: str | None = None) -> aiohttp.ClientSession:
541541
session_manager=self.clone(),
542542
snowflake_ocsp_mode=self._cfg.snowflake_ocsp_mode,
543543
)
544-
# 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
545-
proxy = (
546-
None
547-
if should_bypass_proxies(url, no_proxy=self.config.no_proxy)
548-
else self.proxy_url
549-
)
544+
545+
proxy_from_conn_params: str | None = None
546+
if not aiohttp.helpers.proxies_from_env():
547+
# TODO: This is only needed because we want to keep compatibility with the synch driver version.
548+
# Otherwise, we could remove that condition and always pass proxy from conn params to the Session constructor.
549+
# But in such case precedence will be reverted and it will overwrite the env vars settings.
550+
551+
# 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
552+
proxy_from_conn_params = (
553+
None
554+
if should_bypass_proxies(url, no_proxy=self.config.no_proxy)
555+
else self.proxy_url
556+
)
550557
# Construct session with base proxy set, request() may override per-URL when bypassing
551558
return self.SessionWithProxy(
552559
connector=connector,
553560
trust_env=self._cfg.trust_env,
554-
proxy=proxy,
561+
proxy=proxy_from_conn_params,
555562
)
556563

557564

test/unit/aio/test_connection_async_unit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ def test_connect_metadata_preservation():
912912
connect_doc == source_doc
913913
), "inspect.getdoc(connect) should match inspect.getdoc(SnowflakeConnection.__init__)"
914914

915-
# Test 8: Check that connect is callable and returns expected type
915+
# Test 8: Check that connect is callable
916916
assert callable(connect), "connect should be callable"
917917

918918
# Test 9: Check type() and __class__ values (important for user introspection)
@@ -933,3 +933,4 @@ def test_connect_metadata_preservation():
933933
assert (
934934
len(params) > 0
935935
), "connect should have parameters from SnowflakeConnection.__init__"
936+
# Should have parameters like account, user, password, etc.

test/unit/aio/test_proxies_async.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ async def test_proxy_env_vars_take_precedence_over_connection_params(
627627
wiremock_generic_mappings_dir,
628628
proxy_env_vars,
629629
monkeypatch,
630+
host_port_pooling,
631+
fix_aiohttp_proxy_bypass,
630632
):
631633
"""Verify that proxy_host/proxy_port connection parameters take precedence over env vars.
632634

0 commit comments

Comments
 (0)