Skip to content

Commit

Permalink
Expose ocsp_fail_open as a parameter
Browse files Browse the repository at this point in the history
We only pass along the parameter when it's set so that we can defer to
the builtin default of the snowflake-connector-python (historically the
default has changed between versions).
  • Loading branch information
jcrobak committed Feb 5, 2025
1 parent 3db63ea commit 8e2cdff
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions dbt-snowflake/src/dbt/adapters/snowflake/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class SnowflakeCredentials(Credentials):
insecure_mode: Optional[bool] = False
# this needs to default to `None` so that we can tell if the user set it; see `__post_init__()`
reuse_connections: Optional[bool] = None
ocsp_fail_open: Optional[bool] = None

def __post_init__(self):
if self.authenticator != "oauth" and (self.oauth_client_secret or self.oauth_client_id):
Expand Down Expand Up @@ -179,6 +180,7 @@ def _connection_keys(self):
"retry_all",
"insecure_mode",
"reuse_connections",
"ocsp_fail_open",
)

def auth_args(self):
Expand Down Expand Up @@ -377,6 +379,11 @@ def connect():
rec_mode = get_record_mode_from_env()
handle = None
if rec_mode != RecorderMode.REPLAY:
ocsp_fail_open_arg = (
{"ocsp_fail_open": creds.ocsp_fail_open}
if creds.ocsp_fail_open is not None
else {}
)
handle = snowflake.connector.connect(
account=creds.account,
database=creds.database,
Expand All @@ -389,6 +396,7 @@ def connect():
insecure_mode=creds.insecure_mode,
session_parameters=session_parameters,
**creds.auth_args(),
**ocsp_fail_open_arg,
)

if rec_mode is not None:
Expand Down
28 changes: 28 additions & 0 deletions dbt-snowflake/tests/unit/test_snowflake_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,34 @@ def test_authenticator_private_key_string_authentication_no_passphrase(
]
)

def test_set_ocsp_fail_open(self):
self.config.credentials = self.config.credentials.replace(ocsp_fail_open=False)
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",
role=None,
schema="public",
user="test_user",
warehouse="test_warehouse",
private_key=None,
application="dbt",
insecure_mode=False,
session_parameters={},
reuse_connections=True,
ocsp_fail_open=False,
)
]
)


class TestSnowflakeAdapterConversions(TestAdapterConversions):
def test_convert_text_type(self):
Expand Down

0 comments on commit 8e2cdff

Please sign in to comment.