Skip to content

Commit

Permalink
Parametrizing application name for more flexibility
Browse files Browse the repository at this point in the history
  • Loading branch information
PrantikTechie committed Apr 26, 2024
1 parent 2756c18 commit a20c269
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dbt/adapters/snowflake/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class SnowflakeCredentials(Credentials):
retry_all: bool = False
insecure_mode: Optional[bool] = False
reuse_connections: Optional[bool] = None
application: Optional[str] = None

def __post_init__(self):
if self.authenticator != "oauth" and (
Expand Down Expand Up @@ -352,7 +353,7 @@ def connect():
role=creds.role,
autocommit=True,
client_session_keep_alive=creds.client_session_keep_alive,
application="dbt",
application=creds.application if creds.application else "dbt",
insecure_mode=creds.insecure_mode,
session_parameters=session_parameters,
**creds.auth_args(),
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/test_snowflake_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,36 @@ def test_query_tag(self):
]
)

def test_application(self):
self.config.credentials = self.config.credentials.replace(
password="test_password", query_tag="test_application"
)
self.adapter = SnowflakeAdapter(self.config, get_context("spawn"))
conn = self.adapter.connections.set_connection_name(name="new_connection_with_new_config")

self.snowflake.assert_not_called()
conn.handle
self.snowflake.assert_has_calls(
[
mock.call(
account="test_account",
autocommit=True,
client_session_keep_alive=False,
database="test_database",
password="test_password",
role=None,
schema="public",
user="test_user",
warehouse="test_warehouse",
private_key=None,
application="test_application",
insecure_mode=False,
session_parameters={},
reuse_connections=None,
)
]
)

def test_reuse_connections_with_keep_alive(self):
self.config.credentials = self.config.credentials.replace(
reuse_connections=True, client_session_keep_alive=True
Expand Down

0 comments on commit a20c269

Please sign in to comment.