MagicStack / MagicStack/asyncpg

Note which kwargs are safe to pass to Pool.set_connect_args

Open
#439 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
8.1k
Forks
468
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked asyncpg.pool.Pool.set_connect_args API documentation and the referenced asyncpg/pool.py lines 459-463. Update the documentation to identify loop and connection_class as kwargs that are already supplied by the pool and cannot be passed safely. Verify the resulting API documentation and ensure the warning matches the observed TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
databases, documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.