Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an unexpected exception when using dsn without username & password #1134

Merged
merged 3 commits into from
Mar 24, 2024

Conversation

willww64
Copy link
Contributor

@willww64 willww64 commented Oct 11, 2023

Description

When the -u, --user flag is not provided and a DSN without the user:pass@ part is used (such as mysql://localhost:3306/mydb), an unexpected exception occurs. The expected behavior should be fallback to the current logged-in user (line 420 of main.py, in the connect method).

This is caused by an unchecked None value for uri.username. This pull request fixes this bug.

Example exception output:

$ mycli mysql://localhost:3306/mydb
Traceback (most recent call last):
  File "/usr/bin/mycli", line 33, in <module>
    sys.exit(load_entry_point('mycli==1.27.0', 'console_scripts', 'mycli')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mycli/main.py", line 1282, in cli
    user = unquote(uri.username)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/urllib/parse.py", line 671, in unquote
    if '%' not in string:
       ^^^^^^^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not iterable

Checklist

  • I've added this contribution to the changelog.md.
  • I've added my name to the AUTHORS file (or it's already there).

Signed-off-by: Will Wang <willww64@gmail.com>
@willww64 willww64 changed the title fix unexpected exception when using dsn without username & password Fix an unexpected exception when using dsn without username & password Oct 11, 2023
@amjith amjith merged commit 4896cae into dbcli:main Mar 24, 2024
3 of 5 checks passed
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