Skip to content

Improve distinguishing between DSNs and databases - #2082

Merged
rolandwalker merged 1 commit into
mainfrom
RW/positional-and-explicit-dsn-vs-database
Aug 1, 2026
Merged

Improve distinguishing between DSNs and databases#2082
rolandwalker merged 1 commit into
mainfrom
RW/positional-and-explicit-dsn-vs-database

Conversation

@rolandwalker

@rolandwalker rolandwalker commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Description

We accept DSNs, both as literals and as aliases, as arguments to --database, as well as to --dsn. This might have been a mistake. The code is complex to support all cases, including the positional case, with selective overrides.

In short, while there are many edge cases, the user must be able to run

mycli --database alias

for backward compatibility with this feature. However, the user should also be able to override the database when connecting to a DSN, so

mycli alias --database overridden

should also be accepted.

However, note that the existing heuristic is that in the case of combination with flags which specify the coordinates of the server

mycli alias --user username

we make a different assumption: alias must refer to a database name, not a DSN. That heuristic may not be ideal, but is left in place for backward compatibility. We might consider changing it. The heuristic might require instead that all relevant coordinates be specified, instead of just one.

We also clarify here the CLI argument names dbname and database internally, to database (corresponding to the option name) and positional_database (since this is the positional value).

Finally, when an explicit --dsn is used, the user definitely wants a DSN, not a database name.

Incidentally, remove an outdated comment.

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the AUTHORS 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 .

@rolandwalker rolandwalker self-assigned this Aug 1, 2026
@rolandwalker
rolandwalker force-pushed the RW/positional-and-explicit-dsn-vs-database branch 3 times, most recently from 8102b1a to 6d6b53a Compare August 1, 2026 12:40
We accept DSNs, both as literals and as aliases, as arguments to
--database, as well as to --dsn.  This might have been a mistake.  The
code is complex to support all cases, including the positional case,
with selective overrides.

In short, while there are many edge cases, the user must be able to run

    mycli --database alias

for backward compatibility with this feature.  However, the user should
also be able to override the database when connecting to a DSN, so

    mycli alias --database overridden

should also be accepted.

However, note that the existing heuristic is that in the case of
combination with flags which specify the coordinates of the server

    mycli alias --user username

we make a different assumption: "alias" must refer to a database name,
not a DSN.  That heuristic may not be ideal, but is left in place for
backward compatibility.  We might consider changing it.  The heuristic
might require instead that _all_ relevant coordinates be specified,
instead of just one.

We also clarify here the CLI argument names dbname and database
internally, to database (corresponding to the option name) and
positional_database (since this is the positional value).

Finally, when an explicit --dsn is used, the user definitely wants a
DSN, not a database name.

Incidentally, remove an outdated comment.
@rolandwalker
rolandwalker force-pushed the RW/positional-and-explicit-dsn-vs-database branch from 6d6b53a to cd0c0f3 Compare August 1, 2026 12:43
@rolandwalker
rolandwalker merged commit 72b77b7 into main Aug 1, 2026
11 checks passed
@rolandwalker
rolandwalker deleted the RW/positional-and-explicit-dsn-vs-database branch August 1, 2026 12:50
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.

1 participant