Skip to content

Bracket IPv6 hosts in the DSN shown and saved by \dsn - #2431

Merged
rolandwalker merged 3 commits into
dbcli:mainfrom
Kernel-Hunter:fix-dsn-ipv6-host
Nov 14, 2026
Merged

rolandwalker merged 3 commits into
dbcli:mainfrom
Kernel-Hunter:fix-dsn-ipv6-host

Conversation

@Kernel-Hunter

Copy link
Copy Markdown
Contributor

Description

When connected to an IPv6 host, \dsn show prints mysql://alice@::1:3307/prod and \dsn save stores that string. The host isn't bracketed, so it can't be read back: urlparse(...).port raises ValueError: Port could not be cast to integer value as ':1:3307', and connecting with the saved alias fails in cli_runner.

format_connection_dsn now wraps a host containing : in brackets, giving mysql://alice@[::1]:3307/prod. urlparse returns hostname ::1 and port 3307 for that, which is what the connect path already expects.

I added test_format_connection_dsn_brackets_ipv6_host. It fails on main and passes with the fix. The rest of mycli_test has the same 63 failures with and without the change on my machine (polars/llm/repl tests that need extras or a server).

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the mycli/AUTHORS.txt file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

format_connection_dsn wrote mysql://alice@::1:3307/prod, which urlparse
cannot read back (port ':1:3307'), so a \dsn save alias for an IPv6
connection failed when used.
@rolandwalker

Copy link
Copy Markdown
Contributor

Hi! Thanks for this!

Merging #2430 has created a merge conflict with this PR. Would you like to fix that, or should I?

@rolandwalker

Copy link
Copy Markdown
Contributor

Should this be changed for prompt escapes too?

@rolandwalker
rolandwalker merged commit 5cbfa43 into dbcli:main Nov 14, 2026
13 checks passed
@rolandwalker

Copy link
Copy Markdown
Contributor

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.

2 participants