Skip to content

Commit

Permalink
Merge pull request #468 from duckdb/jwills_make_secret_construction_t…
Browse files Browse the repository at this point in the history
…hreadsafe

Move the secret creation to a connection-level operation instead of a cursor-level operation
  • Loading branch information
jwills authored Oct 18, 2024
2 parents 02b3b86 + 0d9da24 commit d0c409b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions dbt/adapters/duckdb/environments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ def initialize_db(
conn.execute(f"install {ext.name} from {ext.repo}")
conn.load_extension(ext.name)

# Create/update secrets on the database
for sql in creds.secrets_sql():
conn.execute(sql)

# Attach any fsspec filesystems on the database
if creds.filesystems:
import fsspec
Expand Down Expand Up @@ -216,9 +220,6 @@ def initialize_cursor(
# to the correct type
cursor.execute(f"SET {key} = '{value}'")

for sql in creds.secrets_sql():
cursor.execute(sql)

# update cursor if something is lost in the copy
# of the parent connection
if plugins:
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_duckdb_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_create_secret(self, connector):
DuckDBConnectionManager.close_all_connections()
connection = self.adapter.acquire_connection("dummy")
assert connection.handle
connection.handle._cursor._cursor.execute.assert_called_with(
connection._handle._env.conn.execute.assert_called_with(
"""CREATE OR REPLACE SECRET _dbt_secret_1 (
type s3,
key_id 'abc',
Expand Down

0 comments on commit d0c409b

Please sign in to comment.