Skip to content

fix: make is_dsn_multihost agree with the connection plan - #64

Merged
lesnik512 merged 1 commit into
mainfrom
fix/is-dsn-multihost-matches-plan
Oct 4, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
fix/is-dsn-multihost-matches-plan

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Closes #36.

is_dsn_multihost and build_connection_plan each decided what "multi-host" means. They used different checks, and they disagreed:

DSN query is_dsn_multihost before after build_connection_plan
host=a:5432&host=b:5433 True True fails over to 2 hosts
host=a,b&port=5432,5433 False True fails over to 2 hosts
host=a&host=b (no ports) True raises ArgumentError raises ArgumentError
host=a, a:5432/db, no host False False no failover

Now there is one definition. parse_connect_args(url) runs the asyncpg dialect's parse once and returns the connect args together with the (host, port) pairs to fail over to. build_connection_plan and is_dsn_multihost both use it. is_dsn_multihost is True exactly when the plan would have failover.

The PR also stops documenting the portless multi-host DSN, which the connection factory rejects. That shape was in the build_db_dsn docstring and the test fixtures. They now use host=h1:p1&host=h2:p2.

Release note

Behaviour change in is_dsn_multihost:

  • It now returns True for the comma-separated format, ?host=h1,h2&port=p1,p2.
  • It now raises sqlalchemy.exc.ArgumentError for DSNs the connection factory would reject, for example repeated host params without ports. It used to return True for these.

Testing

  • New tests fail on main: a parametrised check that is_dsn_multihost agrees with build_connection_plan for each DSN shape, the comma format, and the ArgumentError case.
  • I ran the full suite against Postgres 18 locally: 45 passed, 100% coverage. ruff, ty and eof-fixer are clean.

@lesnik512
lesnik512 merged commit 2d88196 into main Oct 4, 2026
12 checks passed
@lesnik512
lesnik512 deleted the fix/is-dsn-multihost-matches-plan branch October 4, 2026 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

is_dsn_multihost and build_connection_plan both decide what "multi-host" means

1 participant