Skip to content

Commit

Permalink
Fix #285. Backwards compatibility for credentials quoting
Browse files Browse the repository at this point in the history
  • Loading branch information
xzkostyan committed Feb 17, 2024
1 parent dc378ec commit 99d1b2b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/sa-versions.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
11 changes: 9 additions & 2 deletions clickhouse_sqlalchemy/drivers/native/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from urllib.parse import quote

from sqlalchemy.sql.elements import TextClause
from sqlalchemy.util import asbool

Expand All @@ -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)
Expand Down Expand Up @@ -50,12 +53,16 @@ def import_dbapi(cls):
return connector

def create_connect_args(self, url):
quote_credentials = sqlalchemy_version < '2.0.24'

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')
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 99d1b2b

Please sign in to comment.