diff --git a/duckdb_engine/config.py b/duckdb_engine/config.py index 41c279b02..353151df6 100644 --- a/duckdb_engine/config.py +++ b/duckdb_engine/config.py @@ -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:") diff --git a/duckdb_engine/tests/test_basic.py b/duckdb_engine/tests/test_basic.py index 15fda1fea..3df3aed94 100644 --- a/duckdb_engine/tests/test_basic.py +++ b/duckdb_engine/tests/test_basic.py @@ -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 @@ -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