Skip to content
Open
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
17 changes: 14 additions & 3 deletions duckdb_engine/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@

@lru_cache()
def get_core_config() -> Set[str]:
# List of connection string parameters that are supported by MotherDuck
# See: https://motherduck.com/docs/key-tasks/authenticating-and-connecting-to-motherduck/authenticating-to-motherduck/
motherduck_config_keys = {"motherduck_token", "attach_mode", "saas_mode"}
# MotherDuck settings that must be passed to duckdb.connect() as config:
# applying them via SET after the connection is established either fails
# with "can only be set during initialization" or happens too late. As
# duckdb settings they carry the motherduck_ prefix; the bare
# attach_mode/saas_mode spellings are only valid inside the md: path
# itself (e.g. "md:db?attach_mode=single") and were never recognized by
# duckdb.connect().
motherduck_config_keys = {
"motherduck_token",
"motherduck_attach_mode",
"motherduck_saas_mode",
"motherduck_session_name",
"motherduck_session_hint", # deprecated alias of motherduck_session_name
}

rows = (
duckdb.connect(":memory:")
Expand Down
15 changes: 15 additions & 0 deletions duckdb_engine/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

from .. import Dialect, insert, supports_attach, supports_user_agent
from .._supports import has_comment_support
from ..config import get_core_config

try:
# sqlalchemy 2
Expand Down Expand Up @@ -706,3 +707,17 @@ def test_register_filesystem() -> None:
with engine.connect() as conn:
duckdb_conn = getattr(conn.connection.dbapi_connection, "_ConnectionWrapper__c")
assert duckdb.list_filesystems(connection=duckdb_conn) == ["memory", "file"]


def test_motherduck_keys_are_connect_time_config() -> None:
core = get_core_config()
assert {
"motherduck_token",
"motherduck_attach_mode",
"motherduck_saas_mode",
"motherduck_session_name",
"motherduck_session_hint",
} <= core
# The bare spellings are md: path parameters, not duckdb settings.
assert "attach_mode" not in core
assert "saas_mode" not in core