Skip to content

Commit 88f621c

Browse files
authored
Merge pull request #691 from Mause/motherduck
fix: allow motherduck to pass their special token parameter at extension load time
2 parents 58200b5 + d4a56fc commit 88f621c

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

duckdb_engine/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def get_core_config() -> Set[str]:
1616
.execute("SELECT name FROM duckdb_settings()")
1717
.fetchall()
1818
)
19-
return {name for name, in rows}
19+
# special case for motherduck here - they accept this config at extension load time
20+
return {name for name, in rows} | {"motherduck_token"}
2021

2122

2223
def apply_config(

duckdb_engine/tests/test_integration.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
import sys
2+
from subprocess import PIPE, Popen
3+
from traceback import print_exc
4+
5+
import duckdb
16
import pandas as pd
7+
from pytest import importorskip, mark, raises
28
from sqlalchemy import text
3-
from sqlalchemy.engine import Engine
9+
from sqlalchemy.engine import Engine, create_engine
10+
from sqlalchemy.exc import ProgrammingError
11+
12+
SEGFAULT = -6
13+
SUCCESS = 0
414

515

616
def test_integration(engine: Engine) -> None:
@@ -12,3 +22,44 @@ def test_integration(engine: Engine) -> None:
1222
execute("register", params) # type: ignore[operator]
1323

1424
conn.execute(text("select * from test_df"))
25+
26+
27+
@mark.remote_data
28+
@mark.skipif(
29+
"dev" in duckdb.__version__, reason="md extension not available for dev builds" # type: ignore[attr-defined]
30+
)
31+
def test_motherduck() -> None:
32+
importorskip("duckdb", "0.7.1")
33+
34+
# we're running this test in a sub process due to occasional segfaults in the motherduck extension
35+
36+
proc = Popen([sys.executable, __file__], stderr=PIPE, stdout=PIPE, text=True)
37+
wait = proc.wait(5000)
38+
assert wait == SUCCESS or wait == SEGFAULT, (proc.stdout, proc.stderr)
39+
40+
41+
def hook() -> None:
42+
try:
43+
_test_motherduck()
44+
except Exception:
45+
print_exc()
46+
sys.exit(-1)
47+
else:
48+
sys.exit(0)
49+
50+
51+
def _test_motherduck() -> None:
52+
engine = create_engine(
53+
"duckdb:///md:motherdb",
54+
connect_args={"config": {"motherduck_token": "motherduckdb_token"}},
55+
)
56+
57+
with raises(
58+
ProgrammingError,
59+
match="Jwt is not in the form of Header.Payload.Signature with two dots and 3 sections",
60+
):
61+
engine.connect()
62+
63+
64+
if __name__ == "__main__":
65+
_test_motherduck()

0 commit comments

Comments
 (0)