Skip to content
This repository has been archived by the owner on May 5, 2022. It is now read-only.

Support connection parameter sessionUser #25

Merged
merged 1 commit into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sqlalchemy_trino/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def create_connect_args(self, url: URL) -> Tuple[List[Any], Dict[str, Any]]:
raise ValueError(f'Unexpected database format {url.database}')

username = kwargs.pop('username', 'anonymous')
kwargs['user'] = username
session_user = kwargs.pop('sessionUser', username)
kwargs['user'] = session_user

password = kwargs.pop('password', None)
if password:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_dialect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from sqlalchemy.engine import url
from sqlalchemy_trino.dialect import TrinoDialect


def test_trino_connection_string_user():
dialect = TrinoDialect()
username = 'test-user'
u = url.make_url(f'trino://{username}@host')
_, cparams = dialect.create_connect_args(u)

assert cparams['user'] == username


def test_trino_connection_string_session_user():
dialect = TrinoDialect()
username = 'test-user'
session_user = 'sess-user'
u = url.make_url(f'trino://{username}@host/?sessionUser={session_user}')
_, cparams = dialect.create_connect_args(u)

assert cparams['user'] == session_user