singlestore-labs / sqlalchemy-singlestoredb

SQLAlchemy dialect for the SingleStore database
Apache License 2.0
2 stars 3 forks source link

"ValueError: Invalid IPv6 URL" when passing password with special characters #7

Open BTheunissen opened 1 week ago

BTheunissen commented 1 week ago

I am currently switching from using mypysql to the singlestore-python client in order to get more granular type information when inspecting tables programmatically. In this instance I am using the library with the SingleStore SQL Alchemy project.

It appears that if certain special characters specifically [ and ] are contained within the user password, then the URL parsing from urllib fails.

I've validated that if I URL encode the [ and ] values to %5B and %5D respectively, the issue still occurs even though if I test the url with urlsplit with Python on my system directly, then it can be successfully split.

I have a feeling that the call at base.py:L386 in the stack trace contains the issue, as we explicitly render the url back as a string which could undo any URL encoding that has been done upstream.

Would be grateful for a fix, thanks!

Stack Trace:

  File "/home/venv/lib/python3.11/site-packages/tap_mysql/client.py", line 57, in create_engine
    return sqlalchemy.create_engine(self.sqlalchemy_url, connect_args=connect_args, echo=False)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 2, in create_engine
  File "/home/venv/lib/python3.11/site-packages/sqlalchemy/util/deprecations.py", line 375, in warned
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/venv/lib/python3.11/site-packages/sqlalchemy/engine/create.py", line 560, in create_engine
    (cargs, cparams) = dialect.create_connect_args(u)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/venv/lib/python3.11/site-packages/sqlalchemy_singlestoredb/base.py", line 386, in create_connect_args
    return [[], build_params(host=url.render_as_string(hide_password=False))]
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/venv/lib/python3.11/site-packages/singlestoredb/connection.py", line 150, in build_params
    urlp = _parse_url(host)
           ^^^^^^^^^^^^^^^^
  File "/home/venv/lib/python3.11/site-packages/singlestoredb/connection.py", line 267, in _parse_url
    parts = urlparse(url, scheme='singlestoredb', allow_fragments=True)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cpython-3.11.6-macos-aarch64-none/lib/python3.11/urllib/parse.py", line 395, in urlparse
    splitresult = urlsplit(url, scheme, allow_fragments)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/python/cpython-3.11.6-macos-aarch64-none/lib/python3.11/urllib/parse.py", line 497, in urlsplit
    raise ValueError("Invalid IPv6 URL")
ValueError: Invalid IPv6 URL
kesmit13 commented 1 week ago

This could be something in the SingleStore SQLAlchemy dialect, or maybe the SingleStoreDB client itself. What version of the client are you running?

BTheunissen commented 1 week ago

I am running the latest release of SingleStore SQLAlchemy 1.1.1, and SingleStore Client 1.7.2.