Skip to content

Commit 29b2263

Browse files
authored
fix: fix pydantic import but moving duckdb attach earlier (#4049)
1 parent 3a57ea2 commit 29b2263

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

sqlmesh/core/config/connection.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,30 @@ def get_catalog(self) -> t.Optional[str]:
130130
return None
131131

132132

133+
class DuckDBAttachOptions(BaseConfig):
134+
type: str
135+
path: str
136+
read_only: bool = False
137+
token: t.Optional[str] = None
138+
139+
def to_sql(self, alias: str) -> str:
140+
options = []
141+
# 'duckdb' is actually not a supported type, but we'd like to allow it for
142+
# fully qualified attach options or integration testing, similar to duckdb-dbt
143+
if self.type not in ("duckdb", "motherduck"):
144+
options.append(f"TYPE {self.type.upper()}")
145+
if self.read_only:
146+
options.append("READ_ONLY")
147+
# TODO: Add support for Postgres schema. Currently adding it blocks access to the information_schema
148+
alias_sql = (
149+
# MotherDuck does not support aliasing
150+
f" AS {alias}" if not (self.type == "motherduck" or self.path.startswith("md:")) else ""
151+
)
152+
options_sql = f" ({', '.join(options)})" if options else ""
153+
token_sql = "?motherduck_token=" + self.token if self.token else ""
154+
return f"ATTACH '{self.path}{token_sql}'{alias_sql}{options_sql}"
155+
156+
133157
class BaseDuckDBConnectionConfig(ConnectionConfig):
134158
"""Common configuration for the DuckDB-based connections.
135159
@@ -357,30 +381,6 @@ def _static_connection_kwargs(self) -> t.Dict[str, t.Any]:
357381
return {"database": connection_str, "config": custom_user_agent_config}
358382

359383

360-
class DuckDBAttachOptions(BaseConfig):
361-
type: str
362-
path: str
363-
read_only: bool = False
364-
token: t.Optional[str] = None
365-
366-
def to_sql(self, alias: str) -> str:
367-
options = []
368-
# 'duckdb' is actually not a supported type, but we'd like to allow it for
369-
# fully qualified attach options or integration testing, similar to duckdb-dbt
370-
if self.type not in ("duckdb", "motherduck"):
371-
options.append(f"TYPE {self.type.upper()}")
372-
if self.read_only:
373-
options.append("READ_ONLY")
374-
# TODO: Add support for Postgres schema. Currently adding it blocks access to the information_schema
375-
alias_sql = (
376-
# MotherDuck does not support aliasing
377-
f" AS {alias}" if not (self.type == "motherduck" or self.path.startswith("md:")) else ""
378-
)
379-
options_sql = f" ({', '.join(options)})" if options else ""
380-
token_sql = "?motherduck_token=" + self.token if self.token else ""
381-
return f"ATTACH '{self.path}{token_sql}'{alias_sql}{options_sql}"
382-
383-
384384
class DuckDBConnectionConfig(BaseDuckDBConnectionConfig):
385385
"""Configuration for the DuckDB connection."""
386386

tests/core/test_config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,3 +963,11 @@ def test_environment_statements_config(tmp_path):
963963
"@grant_schema_privileges()",
964964
"GRANT REFERENCES ON FUTURE VIEWS IN DATABASE db TO ROLE admin_role;",
965965
]
966+
967+
968+
# https://github.com/TobikoData/sqlmesh/pull/4049
969+
def test_pydantic_import_error() -> None:
970+
class TestConfig(DuckDBConnectionConfig):
971+
pass
972+
973+
TestConfig()

0 commit comments

Comments
 (0)