From 3637ce506f1c8e7e7a44ade59ac9db20c94eb4bb Mon Sep 17 00:00:00 2001 From: "W. Aaron Morris" Date: Wed, 31 Jul 2024 10:17:53 -0500 Subject: [PATCH 1/3] fix(secrets): value should be enclosed in quotes --- dbt/adapters/duckdb/secrets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt/adapters/duckdb/secrets.py b/dbt/adapters/duckdb/secrets.py index 62b1307d..b9d50a58 100644 --- a/dbt/adapters/duckdb/secrets.py +++ b/dbt/adapters/duckdb/secrets.py @@ -47,7 +47,7 @@ def to_sql(self) -> str: params.update(params.pop("secret_kwargs", {})) params_sql = f",\n{tab}".join( [ - f"{key} {value}" + f"{key} '{value}'" for key, value in params.items() if value is not None and key not in ["name", "persistent"] ] From 5884da5c726be2c41ea54b5e6c4c0e6cca68ae4b Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Wed, 31 Jul 2024 10:22:09 -0700 Subject: [PATCH 2/3] add quotes when secret params are not type or provider --- dbt/adapters/duckdb/secrets.py | 2 +- tests/unit/test_credentials.py | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/dbt/adapters/duckdb/secrets.py b/dbt/adapters/duckdb/secrets.py index b9d50a58..243c99e6 100644 --- a/dbt/adapters/duckdb/secrets.py +++ b/dbt/adapters/duckdb/secrets.py @@ -47,7 +47,7 @@ def to_sql(self) -> str: params.update(params.pop("secret_kwargs", {})) params_sql = f",\n{tab}".join( [ - f"{key} '{value}'" + f"{key} '{value}'" if key not in ["type", "provider"] else f"{key} {value}" for key, value in params.items() if value is not None and key not in ["name", "persistent"] ] diff --git a/tests/unit/test_credentials.py b/tests/unit/test_credentials.py index 72c5b8a3..fd0756a3 100644 --- a/tests/unit/test_credentials.py +++ b/tests/unit/test_credentials.py @@ -38,9 +38,9 @@ def test_add_secret_with_empty_name(): assert sql == \ """CREATE SECRET ( type s3, - key_id abc, - secret xyz, - region us-west-2 + key_id 'abc', + secret 'xyz', + region 'us-west-2' )""" @@ -68,10 +68,10 @@ def test_add_secret_with_name(): assert sql == \ """CREATE OR REPLACE SECRET my_secret ( type s3, - scope s3://my-bucket, - key_id abc, - secret xyz, - region us-west-2 + scope 's3://my-bucket', + key_id 'abc', + secret 'xyz', + region 'us-west-2' )""" @@ -107,7 +107,7 @@ def test_add_unsupported_secret_param(): assert sql == \ """CREATE OR REPLACE SECRET _dbt_secret_1 ( type s3, - password secret + password 'secret' )""" with pytest.raises(duckdb.BinderException) as e: duckdb.sql(sql) @@ -141,10 +141,10 @@ def test_add_azure_secret(): """CREATE SECRET ( type azure, provider service_principal, - tenant_id abc, - client_id xyz, - client_certificate_path foo\\bar\\baz.pem, - account_name 123 + tenant_id 'abc', + client_id 'xyz', + client_certificate_path 'foo\\bar\\baz.pem', + account_name '123' )""" @@ -166,7 +166,7 @@ def test_add_hf_secret(): assert sql == \ """CREATE SECRET ( type huggingface, - token abc + token 'abc' )""" From b89a5c06c0ca3517013ec482643e1ad6b12988e6 Mon Sep 17 00:00:00 2001 From: Guen Prawiroatmodjo Date: Wed, 31 Jul 2024 11:50:58 -0700 Subject: [PATCH 3/3] update test --- tests/unit/test_duckdb_adapter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_duckdb_adapter.py b/tests/unit/test_duckdb_adapter.py index 43fba6c0..f0942938 100644 --- a/tests/unit/test_duckdb_adapter.py +++ b/tests/unit/test_duckdb_adapter.py @@ -118,7 +118,7 @@ def test_create_secret(self, connector): connection.handle._cursor._cursor.execute.assert_called_with( """CREATE OR REPLACE SECRET _dbt_secret_1 ( type s3, - key_id abc, - secret xyz, - region us-west-2 + key_id 'abc', + secret 'xyz', + region 'us-west-2' )""")