Skip to content

Commit 5f9cf58

Browse files
fix!: consolidate to 'ip_type' instead of 'ip_types' for connect args (#220)
1 parent 390be2d commit 5f9cf58

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Example:
103103
connector.connect(
104104
"project:region:instance",
105105
"pymysql",
106-
ip_types=IPTypes.PRIVATE # Prefer private IP
106+
ip_type=IPTypes.PRIVATE # Prefer private IP
107107
... insert other kwargs ...
108108
)
109109
```
@@ -147,7 +147,7 @@ connector.connect(
147147
db="my_database",
148148
active_directory_auth=True,
149149
server_name="private.[instance].[location].[project].cloudsql.[domain]",
150-
ip_types=IPTypes.PRIVATE
150+
ip_type=IPTypes.PRIVATE
151151
)
152152
```
153153

google/cloud/sql/connector/connector.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
class Connector:
3434
"""A class to configure and create connections to Cloud SQL instances.
3535
36-
:type ip_types: IPTypes
37-
:param ip_types
36+
:type ip_type: IPTypes
37+
:param ip_type
3838
The IP type (public or private) used to connect. IP types
3939
can be either IPTypes.PUBLIC or IPTypes.PRIVATE.
4040
@@ -54,7 +54,7 @@ class Connector:
5454

5555
def __init__(
5656
self,
57-
ip_types: IPTypes = IPTypes.PUBLIC,
57+
ip_type: IPTypes = IPTypes.PUBLIC,
5858
enable_iam_auth: bool = False,
5959
timeout: int = 30,
6060
credentials: Optional[Credentials] = None,
@@ -70,7 +70,7 @@ def __init__(
7070
# set default params for connections
7171
self._timeout = timeout
7272
self._enable_iam_auth = enable_iam_auth
73-
self._ip_types = ip_types
73+
self._ip_type = ip_type
7474
self._credentials = credentials
7575

7676
def connect(
@@ -123,15 +123,22 @@ def connect(
123123
)
124124
self._instances[instance_connection_string] = icm
125125

126-
ip_types = kwargs.pop("ip_types", self._ip_types)
126+
if "ip_types" in kwargs:
127+
ip_type = kwargs.pop("ip_types")
128+
logger.warning(
129+
"Deprecation Warning: Parameter `ip_types` is deprecated and may be removed"
130+
"in a future release. Please use `ip_type` instead."
131+
)
132+
else:
133+
ip_type = kwargs.pop("ip_type", self._ip_type)
127134
if "timeout" in kwargs:
128-
return icm.connect(driver, ip_types, **kwargs)
135+
return icm.connect(driver, ip_type, **kwargs)
129136
elif "connect_timeout" in kwargs:
130137
timeout = kwargs["connect_timeout"]
131138
else:
132139
timeout = self._timeout
133140
try:
134-
return icm.connect(driver, ip_types, timeout, **kwargs)
141+
return icm.connect(driver, ip_type, timeout, **kwargs)
135142
except Exception as e:
136143
# with any other exception, we attempt a force refresh, then throw the error
137144
icm.force_refresh()

tests/system/test_ip_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
table_name = f"books_{uuid.uuid4().hex}"
2626

2727

28-
def init_connection_engine(ip_types: IPTypes) -> sqlalchemy.engine.Engine:
28+
def init_connection_engine(ip_type: IPTypes) -> sqlalchemy.engine.Engine:
2929
def getconn() -> pymysql.connections.Connection:
3030
conn: pymysql.connections.Connection = connector.connect(
3131
os.environ["MYSQL_CONNECTION_NAME"],
3232
"pymysql",
33-
ip_types=ip_types,
33+
ip_type=ip_type,
3434
user=os.environ["MYSQL_USER"],
3535
password=os.environ["MYSQL_PASS"],
3636
db=os.environ["MYSQL_DB"],

0 commit comments

Comments
 (0)