Skip to content

Commit 5a15e6f

Browse files
committed
fix(dlt): handle ducklake destination without raising Unknown connection type
1 parent 3df452c commit 5a15e6f

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

‎sqlmesh/integrations/dlt.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def generate_dlt_models_and_settings(
6060

6161
# Get the connection credentials
6262
db_type = pipeline.destination.to_name(pipeline.destination)
63-
if db_type == "filesystem":
63+
if db_type in ("filesystem", "ducklake"):
6464
connection_config = None
6565
else:
6666
client = pipeline.destination_client()

‎tests/integrations/test_dlt.py‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,64 @@ def test_generate_incremental_model_filters_on_timestamp_macros() -> None:
1919
assert "BETWEEN @start_ts AND @end_ts" in model
2020
assert "@start_ds" not in model
2121
assert "@end_ds" not in model
22+
23+
24+
def test_generate_dlt_models_and_settings_supports_ducklake_destination(monkeypatch) -> None:
25+
import sys
26+
import types
27+
from sqlmesh.integrations.dlt import generate_dlt_models_and_settings
28+
29+
class _FakeDestination:
30+
@staticmethod
31+
def to_name(_dest) -> str:
32+
return "ducklake"
33+
34+
class _FakeSchema:
35+
loads_table_name = "_dlt_loads"
36+
_dlt_tables_prefix = "_dlt_"
37+
tables = {
38+
"items": {
39+
"columns": {
40+
"id": {"name": "id", "data_type": "bigint", "primary_key": True},
41+
"_dlt_load_id": {"name": "_dlt_load_id", "data_type": "text"},
42+
}
43+
}
44+
}
45+
46+
class _FakePipeline:
47+
destination = _FakeDestination()
48+
default_schema = _FakeSchema()
49+
dataset_name = "mre"
50+
51+
def _get_load_storage(self):
52+
return types.SimpleNamespace(list_loaded_packages=lambda: [])
53+
54+
dlt_mod = types.ModuleType("dlt")
55+
dlt_mod.__path__ = []
56+
dlt_mod.attach = lambda **kwargs: _FakePipeline()
57+
dlt_pipeline_pkg = types.ModuleType("dlt.pipeline")
58+
dlt_pipeline_exc = types.ModuleType("dlt.pipeline.exceptions")
59+
dlt_pipeline_exc.CannotRestorePipelineException = Exception
60+
dlt_common = types.ModuleType("dlt.common")
61+
dlt_pipeline = types.ModuleType("dlt.common.pipeline")
62+
dlt_pipeline.get_dlt_pipelines_dir = lambda: "/tmp/dlt"
63+
dlt_schema = types.ModuleType("dlt.common.schema")
64+
dlt_schema_utils = types.ModuleType("dlt.common.schema.utils")
65+
dlt_schema_utils.is_complete_column = lambda col: bool(col.get("name") and col.get("data_type"))
66+
dlt_schema_utils.has_table_seen_data = lambda table: True
67+
68+
for name, mod in [
69+
("dlt", dlt_mod),
70+
("dlt.pipeline", dlt_pipeline_pkg),
71+
("dlt.pipeline.exceptions", dlt_pipeline_exc),
72+
("dlt.common", dlt_common),
73+
("dlt.common.pipeline", dlt_pipeline),
74+
("dlt.common.schema", dlt_schema),
75+
("dlt.common.schema.utils", dlt_schema_utils),
76+
]:
77+
monkeypatch.setitem(sys.modules, name, mod)
78+
79+
models, connection_config, start_date = generate_dlt_models_and_settings("mre_ducklake", "duckdb")
80+
assert connection_config is None
81+
assert start_date
82+
assert any(name == "mre_sqlmesh.incremental_items" for name, _ in models)

0 commit comments

Comments
 (0)