From 5a15e6f044f0cb01708d4a63af56037c35d77bec Mon Sep 17 00:00:00 2001 From: boomesh11 Date: Mon, 16 Nov 2026 17:04:18 +0530 Subject: [PATCH] fix(dlt): handle ducklake destination without raising Unknown connection type --- sqlmesh/integrations/dlt.py | 2 +- tests/integrations/test_dlt.py | 61 ++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/sqlmesh/integrations/dlt.py b/sqlmesh/integrations/dlt.py index d9cced8deb..9b5bca46ff 100644 --- a/sqlmesh/integrations/dlt.py +++ b/sqlmesh/integrations/dlt.py @@ -60,7 +60,7 @@ def generate_dlt_models_and_settings( # Get the connection credentials db_type = pipeline.destination.to_name(pipeline.destination) - if db_type == "filesystem": + if db_type in ("filesystem", "ducklake"): connection_config = None else: client = pipeline.destination_client() diff --git a/tests/integrations/test_dlt.py b/tests/integrations/test_dlt.py index ca4f374acb..0d83a21484 100644 --- a/tests/integrations/test_dlt.py +++ b/tests/integrations/test_dlt.py @@ -19,3 +19,64 @@ def test_generate_incremental_model_filters_on_timestamp_macros() -> None: assert "BETWEEN @start_ts AND @end_ts" in model assert "@start_ds" not in model assert "@end_ds" not in model + + +def test_generate_dlt_models_and_settings_supports_ducklake_destination(monkeypatch) -> None: + import sys + import types + from sqlmesh.integrations.dlt import generate_dlt_models_and_settings + + class _FakeDestination: + @staticmethod + def to_name(_dest) -> str: + return "ducklake" + + class _FakeSchema: + loads_table_name = "_dlt_loads" + _dlt_tables_prefix = "_dlt_" + tables = { + "items": { + "columns": { + "id": {"name": "id", "data_type": "bigint", "primary_key": True}, + "_dlt_load_id": {"name": "_dlt_load_id", "data_type": "text"}, + } + } + } + + class _FakePipeline: + destination = _FakeDestination() + default_schema = _FakeSchema() + dataset_name = "mre" + + def _get_load_storage(self): + return types.SimpleNamespace(list_loaded_packages=lambda: []) + + dlt_mod = types.ModuleType("dlt") + dlt_mod.__path__ = [] + dlt_mod.attach = lambda **kwargs: _FakePipeline() + dlt_pipeline_pkg = types.ModuleType("dlt.pipeline") + dlt_pipeline_exc = types.ModuleType("dlt.pipeline.exceptions") + dlt_pipeline_exc.CannotRestorePipelineException = Exception + dlt_common = types.ModuleType("dlt.common") + dlt_pipeline = types.ModuleType("dlt.common.pipeline") + dlt_pipeline.get_dlt_pipelines_dir = lambda: "/tmp/dlt" + dlt_schema = types.ModuleType("dlt.common.schema") + dlt_schema_utils = types.ModuleType("dlt.common.schema.utils") + dlt_schema_utils.is_complete_column = lambda col: bool(col.get("name") and col.get("data_type")) + dlt_schema_utils.has_table_seen_data = lambda table: True + + for name, mod in [ + ("dlt", dlt_mod), + ("dlt.pipeline", dlt_pipeline_pkg), + ("dlt.pipeline.exceptions", dlt_pipeline_exc), + ("dlt.common", dlt_common), + ("dlt.common.pipeline", dlt_pipeline), + ("dlt.common.schema", dlt_schema), + ("dlt.common.schema.utils", dlt_schema_utils), + ]: + monkeypatch.setitem(sys.modules, name, mod) + + models, connection_config, start_date = generate_dlt_models_and_settings("mre_ducklake", "duckdb") + assert connection_config is None + assert start_date + assert any(name == "mre_sqlmesh.incremental_items" for name, _ in models)