@@ -150,19 +150,24 @@ def __post_init__(self):
150150 raise ValueError ("Instance connection URI cannot be empty" )
151151
152152 def get_connector_handler (self ) -> Callable [[], DBAPIConnection ]:
153- cloudsql_client = CloudSQLConnector (
154- refresh_strategy = self .refresh_strategy ,
155- ** self .connector_kwargs )
153+ """Returns a function that creates a new database connection.
156154
157- cloudsql_connector = lambda : cloudsql_client .connect (
158- instance_connection_string = self .instance_connection_uri ,
159- driver = self .db_adapter .value ,
160- user = self .user ,
161- password = self .password ,
162- db = self .db_id ,
163- ** self .connect_kwargs )
155+ The returned connector function creates database connections that should
156+ be properly closed by the caller when no longer needed.
157+ """
158+ cloudsql_client = CloudSQLConnector (
159+ refresh_strategy = self .refresh_strategy ,
160+ ** self .connector_kwargs )
164161
165- return cloudsql_connector
162+ cloudsql_connector = lambda : cloudsql_client .connect (
163+ instance_connection_string = self .instance_connection_uri ,
164+ driver = self .db_adapter .value ,
165+ user = self .user ,
166+ password = self .password ,
167+ db = self .db_id ,
168+ ** self .connect_kwargs )
169+
170+ return cloudsql_connector
166171
167172 def get_db_url (self ) -> str :
168173 return self .db_adapter .to_sqlalchemy_dialect () + "://"
@@ -195,22 +200,23 @@ def __post_init__(self):
195200 raise ValueError ("Database host cannot be empty" )
196201
197202 def get_connector_handler (self ) -> Callable [[], DBAPIConnection ]:
203+ """Returns a function that creates a new database connection.
204+
205+ The returned connector function creates database connections that should
206+ be properly closed by the caller when no longer needed.
207+ """
198208 if self .db_adapter == DatabaseTypeAdapter .POSTGRESQL :
199- # It is automatically closed upstream by sqlalchemy context manager.
200209 sql_connector = lambda : pg8000 .connect (
201210 host = self .host , port = self .port , database = self .db_id ,
202211 user = self .user , password = self .password , ** self .connect_kwargs )
203212 elif self .db_adapter == DatabaseTypeAdapter .MYSQL :
204- # It is automatically closed upstream by sqlalchemy context manager.
205213 sql_connector = lambda : pymysql .connect (
206214 host = self .host , port = self .port , database = self .db_id ,
207215 user = self .user , password = self .password , ** self .connect_kwargs )
208216 elif self .db_adapter == DatabaseTypeAdapter .SQLSERVER :
209- # It is automatically closed upstream by sqlalchemy context manager.
210217 sql_connector = lambda : pytds .connect (
211218 dsn = self .host , port = self .port , database = self .db_id , user = self .user ,
212219 password = self .password , ** self .connect_kwargs )
213-
214220 return sql_connector
215221
216222 def get_db_url (self ) -> str :
0 commit comments