xzkostyan / clickhouse-sqlalchemy

ClickHouse dialect for SQLAlchemy
https://clickhouse-sqlalchemy.readthedocs.io
Other
418 stars 122 forks source link

Error connecting with the database when password contains a special character (+%...) with native engine. #291

Open marcvivancos opened 5 months ago

marcvivancos commented 5 months ago

Describe the bug The bug is when there is a special character in the password, the problem seems to be in the file drives/native/base.py where the password and the username get quote two times. First in the function create_connect_args and then in the render_as_string method from sqlalchemy url:

    def create_connect_args(self, url):
        url = url.set(drivername='clickhouse')
        if url.username:
            url = url.set(username=quote(url.username))

        if url.password:
            url = url.set(password=quote(url.password))

        self.engine_reflection = asbool(
            url.query.get('engine_reflection', 'true')
        )

        return (url.render_as_string(hide_password=False), ), {}

So a password 123+X becomes 123%252BX when it should be 123%2BX

To Reproduce

from sqlalchemy import text
from sqlalchemy.engine import create_engine

if __name__ == "__main__":
    url = "clickhouse+native://default:123+X@localhost:9000/default"
    engine = create_engine(url)
    with engine.connect() as conn:
        conn.execute(text("SELECT version();"))

Expected behavior Correctly connect to the database with a password with a special character

Versions

jfmlima commented 4 months ago

This https://github.com/xzkostyan/clickhouse-sqlalchemy/commit/4a4931f6b4b346b7843ec6b3495fc796c209cfbb commit fixes this right?