From 48a7384bb4a663d0c47c3bdf94df63ca6c730071 Mon Sep 17 00:00:00 2001 From: eakmanrq <6326532+eakmanrq@users.noreply.github.com> Date: Thu, 28 Aug 2025 13:58:17 -0700 Subject: [PATCH] fix: pydantic v1 issues with dbt 1.6 semantic models --- .github/workflows/pr.yaml | 39 +++++++++++++++++++ sqlmesh/dbt/manifest.py | 9 +++++ .../fixtures/dbt/sushi_test/models/schema.yml | 20 ++++++++++ 3 files changed, 68 insertions(+) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 65c45b38e5..ad187df449 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -92,6 +92,44 @@ jobs: # of DuckDB require a version of DuckDB we no longer support run: | source .venv/bin/activate + + # Remove semantic_models and metrics sections for DBT versions < 1.6.0 + # Using explicit list to avoid version comparison issues + if [[ "${{ matrix.dbt-version }}" == "1.3" ]] || \ + [[ "${{ matrix.dbt-version }}" == "1.4" ]] || \ + [[ "${{ matrix.dbt-version }}" == "1.5" ]]; then + + echo "DBT version is ${{ matrix.dbt-version }} (< 1.6.0), removing semantic_models and metrics sections..." + + schema_file="tests/fixtures/dbt/sushi_test/models/schema.yml" + if [[ -f "$schema_file" ]]; then + echo "Modifying $schema_file..." + + # Create a temporary file + temp_file=$(mktemp) + + # Use awk to remove semantic_models and metrics sections + awk ' + /^semantic_models:/ { in_semantic=1; next } + /^metrics:/ { in_metrics=1; next } + /^[^ ]/ && (in_semantic || in_metrics) { + in_semantic=0; + in_metrics=0 + } + !in_semantic && !in_metrics { print } + ' "$schema_file" > "$temp_file" + + # Move the temp file back + mv "$temp_file" "$schema_file" + + echo "Successfully removed semantic_models and metrics sections" + else + echo "Schema file not found at $schema_file, skipping..." + fi + else + echo "DBT version is ${{ matrix.dbt-version }} (>= 1.6.0), keeping semantic_models and metrics sections" + fi + make dbt-fast-test - name: Test SQLMesh info in sushi_dbt working-directory: ./examples/sushi_dbt @@ -104,4 +142,5 @@ jobs: else echo "DBT version is ${{ matrix.dbt-version }} (>= 1.5.0), keeping version parameters" fi + sqlmesh info --skip-connection diff --git a/sqlmesh/dbt/manifest.py b/sqlmesh/dbt/manifest.py index bc7660f4ce..edb9004d6f 100644 --- a/sqlmesh/dbt/manifest.py +++ b/sqlmesh/dbt/manifest.py @@ -80,6 +80,13 @@ IGNORED_PACKAGES = {"elementary"} BUILTIN_CALLS = {*BUILTIN_GLOBALS, *BUILTIN_FILTERS} +# Patch Semantic Manifest to skip validation and avoid Pydantic v1 errors on DBT 1.6 +# We patch for 1.7+ since we don't care about semantic models +if DBT_VERSION >= (1, 6, 0): + from dbt.contracts.graph.semantic_manifest import SemanticManifest # type: ignore + + SemanticManifest.validate = lambda _: True # type: ignore + class ManifestHelper: def __init__( @@ -456,6 +463,8 @@ def _load_manifest(self) -> Manifest: register_adapter(runtime_config) # type: ignore manifest = ManifestLoader.get_full_manifest(runtime_config) + # This adapter doesn't care about semantic models so we clear them out to avoid issues + manifest.semantic_models = {} reset_adapters() return manifest diff --git a/tests/fixtures/dbt/sushi_test/models/schema.yml b/tests/fixtures/dbt/sushi_test/models/schema.yml index ac99269207..48b8b814d3 100644 --- a/tests/fixtures/dbt/sushi_test/models/schema.yml +++ b/tests/fixtures/dbt/sushi_test/models/schema.yml @@ -52,3 +52,23 @@ sources: tables: - name: items - name: orders + +semantic_models: + - name: top_waiters + description: Some description + model: ref('top_waiters') + measures: + - name: total_waiters + agg: sum + expr: waiter + dimensions: + - name: waiter + type: categorical + +metrics: + - name: some_waiter_thing + description: Something + type: simple + label: testing + type_params: + measure: total_waiters \ No newline at end of file