Skip to content

Commit bcc68cd

Browse files
chore: allow using static connection info in Connector (#472)
#406 added support for static connection info. But 5d9c473 accidentally deleted actually using the static connection info to create the cache. So re-adding that change in this PR.
1 parent 86d38bb commit bcc68cd

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

google/cloud/alloydbconnector/connector.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from google.cloud.alloydbconnector.instance import RefreshAheadCache
3838
from google.cloud.alloydbconnector.lazy import LazyRefreshCache
3939
import google.cloud.alloydbconnector.pg8000 as pg8000
40+
from google.cloud.alloydbconnector.static import StaticConnectionInfoCache
4041
from google.cloud.alloydbconnector.types import CacheTypes
4142
from google.cloud.alloydbconnector.utils import generate_keys
4243
from google.cloud.alloydbconnector.utils import strip_http_prefix
@@ -188,6 +189,8 @@ async def connect_async(self, instance_uri: str, driver: str, **kwargs: Any) ->
188189
# use existing connection info if possible
189190
if instance_uri in self._cache:
190191
cache = self._cache[instance_uri]
192+
elif self._static_conn_info:
193+
cache = StaticConnectionInfoCache(instance_uri, self._static_conn_info)
191194
else:
192195
if self._refresh_strategy == RefreshStrategy.LAZY:
193196
logger.debug(

tests/unit/test_connector.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ def test_Connector_static_connection_info(
321321
)
322322
# check connection is returned
323323
assert connection is True
324+
# check that cache is not set
325+
assert fake_client.instance.uri() not in connector._cache
324326

325327

326328
def test_connect_when_closed(credentials: FakeCredentials) -> None:

0 commit comments

Comments
 (0)