Skip to content

fix(motherduck): support motherduck_token in settings for direct profiles#734

Open
mjkanji wants to merge 1 commit into
duckdb:masterfrom
mjkanji:fix/direct-motherduck-settings-token
Open

fix(motherduck): support motherduck_token in settings for direct profiles#734
mjkanji wants to merge 1 commit into
duckdb:masterfrom
mjkanji:fix/direct-motherduck-settings-token

Conversation

@mjkanji

@mjkanji mjkanji commented Apr 29, 2026

Copy link
Copy Markdown

Fixes #733.

What

For direct MotherDuck profiles (path: "md:my_db"), motherduck_token in creds.settings was neither consumed at connect time nor popped from settings, so initialize_cursor would later re-issue SET motherduck_token = '...' on the already-open connection — which the MotherDuck extension rejects as init-only:

Runtime Error
  setting 'motherduck_token' can only be set during initialization

The attach branch already handled this correctly in configure_connection (set + pop). This PR mirrors that behavior in update_connection_config for the direct branch: merge MD keys from creds.settings into the connect config and pop them out of creds.settings so they aren't re-applied via SET post-init.

Test

Adds TestMDPluginWithSettings to tests/functional/plugins/motherduck/test_motherduck.py as a direct-mode counterpart to TestMDPluginAttachWithSettings. It subclasses TestMDPlugin to reuse all model and assertion coverage with the settings-based profile shape.

The mocked test_motherduck_user_agent continues to pass (verified locally).

Other supported forms — unchanged

  • path: "md:my_db?motherduck_token=..." (worked before, still works)
  • plugins: [{ module: motherduck, config: { token: ... } }] (worked before, still works)

…iles

In direct mode (path: "md:my_db"), motherduck_token in creds.settings was
neither consumed at connect time nor popped from settings, so
initialize_cursor would later re-issue SET motherduck_token = '...' on the
already-open connection — which the MotherDuck extension rejects as
init-only ("setting 'motherduck_token' can only be set during initialization").

Mirror the attach-branch behavior in update_connection_config: merge MD keys
from creds.settings into the connect config and pop them out of
creds.settings so they aren't re-applied via SET post-init.

Adds TestMDPluginWithSettings as a direct-mode counterpart to
TestMDPluginAttachWithSettings, subclassing TestMDPlugin to reuse all model
and assertion coverage with the settings-based profile shape.

Fixes duckdb#733
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Direct MotherDuck profile with motherduck_token in settings fails with "can only be set during initialization"

1 participant