mycli
mycli copied to clipboard
Fix an unexpected exception when using dsn without username & password
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
- [x] I've added this contribution to the
changelog.md. - [x] I've added my name to the
AUTHORSfile (or it's already there).