diff --git a/.github/workflows/sa-versions.yml b/.github/workflows/sa-versions.yml index 27c8be17..53979d6f 100644 --- a/.github/workflows/sa-versions.yml +++ b/.github/workflows/sa-versions.yml @@ -1,5 +1,5 @@ on: [push, pull_request] -name: "SQLAlchemy >=2.0.25 versions" +name: "SQLAlchemy >=2.0.18 versions" jobs: tests: runs-on: ubuntu-20.04 @@ -9,7 +9,7 @@ jobs: - "3.12" clickhouse-version: - 23.8.4.69 - sa-version: [25] + sa-version: [18, 19, 20, 21, 22, 23, 24, 25, 26, 27] name: ${{ matrix.python-version }} SA=2.0.${{ matrix.sa-version }} steps: diff --git a/clickhouse_sqlalchemy/drivers/native/base.py b/clickhouse_sqlalchemy/drivers/native/base.py index 8fe46119..5ac83a6c 100644 --- a/clickhouse_sqlalchemy/drivers/native/base.py +++ b/clickhouse_sqlalchemy/drivers/native/base.py @@ -1,3 +1,5 @@ +from urllib.parse import quote + from sqlalchemy.sql.elements import TextClause from sqlalchemy.util import asbool @@ -6,6 +8,7 @@ ClickHouseDialect, ClickHouseExecutionContextBase, ClickHouseSQLCompiler, ) from sqlalchemy.engine.interfaces import ExecuteStyle +from sqlalchemy import __version__ as sqlalchemy_version # Export connector version VERSION = (0, 0, 2, None) @@ -50,12 +53,16 @@ def import_dbapi(cls): return connector def create_connect_args(self, url): + quote_credentials = sqlalchemy_version < '2.0.25' + url = url.set(drivername='clickhouse') if url.username: - url = url.set(username=url.username) + username = quote(url.username) if quote_credentials else url.username + url = url.set(username=username) if url.password: - url = url.set(password=url.password) + password = quote(url.password) if quote_credentials else url.password + url = url.set(password=password) self.engine_reflection = asbool( url.query.get('engine_reflection', 'true') diff --git a/setup.py b/setup.py index feb675da..d821846e 100644 --- a/setup.py +++ b/setup.py @@ -96,7 +96,7 @@ def read_version(): packages=find_packages('.', exclude=["tests*"]), python_requires='>=3.7, <4', install_requires=[ - 'sqlalchemy>=2.0.25,<2.1.0', + 'sqlalchemy>=2.0.0,<2.1.0', 'requests', 'clickhouse-driver>=0.1.2', 'asynch>=0.2.2',