From b8a8904aadca454386ce5c20f2edfb0abca6f654 Mon Sep 17 00:00:00 2001 From: rhatgadkar-goog Date: Sat, 19 Jul 2025 00:04:00 +0000 Subject: [PATCH 1/2] chore: allow using static connection info in Connector https://github.com/GoogleCloudPlatform/alloydb-python-connector/pull/406 added support for static connection info. But https://github.com/GoogleCloudPlatform/alloydb-python-connector/pull/406/commits/5d9c473adedeb402493cd2d4b547735b51af2124 accidentally deleted actually using the static connection info to create the cache. So re-adding that change in this PR. --- google/cloud/alloydbconnector/connector.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/google/cloud/alloydbconnector/connector.py b/google/cloud/alloydbconnector/connector.py index 9a108164..0b100a82 100644 --- a/google/cloud/alloydbconnector/connector.py +++ b/google/cloud/alloydbconnector/connector.py @@ -37,6 +37,7 @@ from google.cloud.alloydbconnector.instance import RefreshAheadCache from google.cloud.alloydbconnector.lazy import LazyRefreshCache import google.cloud.alloydbconnector.pg8000 as pg8000 +from google.cloud.alloydbconnector.static import StaticConnectionInfoCache from google.cloud.alloydbconnector.types import CacheTypes from google.cloud.alloydbconnector.utils import generate_keys 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) -> # use existing connection info if possible if instance_uri in self._cache: cache = self._cache[instance_uri] + elif self._static_conn_info: + cache = StaticConnectionInfoCache(instance_uri, self._static_conn_info) else: if self._refresh_strategy == RefreshStrategy.LAZY: logger.debug( From 2d07ca5860a9b37f918ab271f66d6e3d0f5cde49 Mon Sep 17 00:00:00 2001 From: rhatgadkar-goog Date: Mon, 21 Jul 2025 16:55:45 +0000 Subject: [PATCH 2/2] add test to verify connection with staticonnectioninfocache --- tests/unit/test_connector.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unit/test_connector.py b/tests/unit/test_connector.py index 11f6b237..349120c6 100644 --- a/tests/unit/test_connector.py +++ b/tests/unit/test_connector.py @@ -321,6 +321,8 @@ def test_Connector_static_connection_info( ) # check connection is returned assert connection is True + # check that cache is not set + assert fake_client.instance.uri() not in connector._cache def test_connect_when_closed(credentials: FakeCredentials) -> None: