asyncpg icon indicating copy to clipboard operation
asyncpg copied to clipboard

Note which kwargs are safe to pass to Pool.set_connect_args

Open adamrothman opened this issue 5 years ago • 1 comments

The documentation for asyncpg.pool.Pool.set_connect_args makes no mention that there are 2 particular kwargs that are already being passed to connect by the pool when it creates new connections: https://github.com/MagicStack/asyncpg/blob/92c2d81256a1efd8cab12c0118d74ccd1c18131b/asyncpg/pool.py#L459-L463

Before reading the source, I incorrectly assumed that any of connect's kwargs are safe to pass to Pool.set_connect_args, but if you pass either loop or connection_class you'll end up with a traceback like this:

Traceback (most recent call last):
... omitted for brevity ...
File "/usr/local/lib/python3.7/site-packages/asyncpg/pool.py", line 762, in __aenter__
self.connection = await self.pool._acquire(self.timeout)
File "/usr/local/lib/python3.7/site-packages/asyncpg/pool.py", line 604, in _acquire
return await _acquire_impl()
File "/usr/local/lib/python3.7/site-packages/asyncpg/pool.py", line 589, in _acquire_impl
proxy = await ch.acquire() # type: PoolConnectionProxy
File "/usr/local/lib/python3.7/site-packages/asyncpg/pool.py", line 133, in acquire
await self.connect()
File "/usr/local/lib/python3.7/site-packages/asyncpg/pool.py", line 125, in connect
self._con = await self._pool._get_new_connection()
File "/usr/local/lib/python3.7/site-packages/asyncpg/pool.py", line 463, in _get_new_connection
**self._connect_kwargs)
TypeError: connect() got multiple values for keyword argument 'loop'

Not hard to fix in my app, but it'd be great to update the docs to maybe save future users some time.

adamrothman avatar May 07 '19 03:05 adamrothman