@@ -313,7 +313,7 @@ class Pool:
313
313
314
314
__slots__ = (
315
315
'_queue' , '_loop' , '_minsize' , '_maxsize' ,
316
- '_init' , '_connect_args' , '_connect_kwargs' ,
316
+ '_init' , '_connect_fn' , ' _connect_args' , '_connect_kwargs' ,
317
317
'_holders' , '_initialized' , '_initializing' , '_closing' ,
318
318
'_closed' , '_connection_class' , '_record_class' , '_generation' ,
319
319
'_setup' , '_max_queries' , '_max_inactive_connection_lifetime'
@@ -329,6 +329,7 @@ def __init__(self, *connect_args,
329
329
loop ,
330
330
connection_class ,
331
331
record_class ,
332
+ connect_fn ,
332
333
** connect_kwargs ):
333
334
334
335
if len (connect_args ) > 1 :
@@ -388,6 +389,7 @@ def __init__(self, *connect_args,
388
389
self ._init = init
389
390
self ._connect_args = connect_args
390
391
self ._connect_kwargs = connect_kwargs
392
+ self ._connect_fn = connect_fn
391
393
392
394
self ._setup = setup
393
395
self ._max_queries = max_queries
@@ -503,7 +505,7 @@ def set_connect_args(self, dsn=None, **connect_kwargs):
503
505
self ._connect_kwargs = connect_kwargs
504
506
505
507
async def _get_new_connection (self ):
506
- con = await connection . connect (
508
+ con = await self . _connect_fn (
507
509
* self ._connect_args ,
508
510
loop = self ._loop ,
509
511
connection_class = self ._connection_class ,
@@ -1097,6 +1099,10 @@ def create_pool(dsn=None, *,
1097
1099
or :meth:`Connection.set_type_codec() <\
1098
1100
asyncpg.connection.Connection.set_type_codec>`.
1099
1101
1102
+ :param coroutine connect_fn:
1103
+ A coroutine with signature identical to :func:`~asyncpg.connection.connect`. This can be used to add custom
1104
+ authentication or ssl logic when creating a connection, as is required by GCP's cloud-sql-python-connector.
1105
+
1100
1106
:param loop:
1101
1107
An asyncio event loop instance. If ``None``, the default
1102
1108
event loop will be used.
@@ -1127,7 +1133,7 @@ def create_pool(dsn=None, *,
1127
1133
return Pool (
1128
1134
dsn ,
1129
1135
connection_class = connection_class ,
1130
- record_class = record_class ,
1136
+ record_class = record_class , connect_fn = connection . connect ,
1131
1137
min_size = min_size , max_size = max_size ,
1132
1138
max_queries = max_queries , loop = loop , setup = setup , init = init ,
1133
1139
max_inactive_connection_lifetime = max_inactive_connection_lifetime ,
0 commit comments