Multihost bug when working with SqlAlchemy
- asyncpg version: 0.24.0
- PostgreSQL version: 10
- Do you use a PostgreSQL SaaS? If so, which? Can you reproduce the issue with a local PostgreSQL install?:
- Python version: 3.9.6
- Platform: Doesn't matter
- Do you use pgbouncer?: No
- Did you install asyncpg with pip?: Yes
- If you built asyncpg locally, which version of Cython did you use?:
- Can the issue be reproduced under both asyncio and uvloop?: doesn't matter
When we use asyncpg via sqlalchemy, we pass a dsn string to sqlalchemy and it parses this string and call asyncpg connect with host, port, username and etc instead of dsn. And it looks like asyncpg can't handle multiple hosts, separated by commas, passed in host param.
self._engine = create_async_engine( dsn, future=True, connect_args={ "statement_cache_size": 0, "dsn": dsn.replace("+asyncpg", ""), "host": None, }, )
It works if I add connect_args, but it looks weird
It's likely an SQLAlchemy bug. The host argument must be a list of strings. /cc @CaselIT, @zzzeek
@Driim could you provide an example of the dsn you are using?
it's not a "bug" in either project, it's a feature request for SQLAlchemy. We support multiple PostgreSQL hosts using the format described at https://docs.sqlalchemy.org/en/14/dialects/postgresql.html#specifying-multiple-fallback-hosts, and this would need to be implemented for our asyncpg dialect.
also see https://github.com/sqlalchemy/sqlalchemy/issues/6083#issuecomment-831654538 for a fun dive into the history of libpq's URL format (hint: it was inspired at least in part by SQLAlchemy).