Skip to content

Commit c92ad02

Browse files
committed
fix: pydantic v1 issues with dbt 1.6 semantic models
1 parent 5011741 commit c92ad02

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

.github/workflows/pr.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,42 @@ jobs:
104104
else
105105
echo "DBT version is ${{ matrix.dbt-version }} (>= 1.5.0), keeping version parameters"
106106
fi
107+
108+
# Remove semantic_models and metrics sections for DBT versions < 1.6.0
109+
# Using explicit list to avoid version comparison issues
110+
if [[ "${{ matrix.dbt-version }}" == "1.3.0" ]] || \
111+
[[ "${{ matrix.dbt-version }}" == "1.4.0" ]] || \
112+
[[ "${{ matrix.dbt-version }}" == "1.5.0" ]]; then
113+
114+
echo "DBT version is ${{ matrix.dbt-version }} (< 1.6.0), removing semantic_models and metrics sections..."
115+
116+
schema_file="../../tests/fixtures/dbt/sushi_test/models/schema.yml"
117+
if [[ -f "$schema_file" ]]; then
118+
echo "Modifying $schema_file..."
119+
120+
# Create a temporary file
121+
temp_file=$(mktemp)
122+
123+
# Use awk to remove semantic_models and metrics sections
124+
awk '
125+
/^semantic_models:/ { in_semantic=1; next }
126+
/^metrics:/ { in_metrics=1; next }
127+
/^[^ ]/ && (in_semantic || in_metrics) {
128+
in_semantic=0;
129+
in_metrics=0
130+
}
131+
!in_semantic && !in_metrics { print }
132+
' "$schema_file" > "$temp_file"
133+
134+
# Move the temp file back
135+
mv "$temp_file" "$schema_file"
136+
137+
echo "Successfully removed semantic_models and metrics sections"
138+
else
139+
echo "Schema file not found at $schema_file, skipping..."
140+
fi
141+
else
142+
echo "DBT version is ${{ matrix.dbt-version }} (>= 1.6.0), keeping semantic_models and metrics sections"
143+
fi
144+
107145
sqlmesh info --skip-connection

sqlmesh/dbt/manifest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@
8080
IGNORED_PACKAGES = {"elementary"}
8181
BUILTIN_CALLS = {*BUILTIN_GLOBALS, *BUILTIN_FILTERS}
8282

83+
# Patch Semantic Manifest to skip validation and avoid Pydantic v1 errors on DBT 1.6
84+
# We patch for 1.7+ since we don't care about semantic models
85+
if DBT_VERSION >= (1, 6, 0):
86+
from dbt.contracts.graph.semantic_manifest import SemanticManifest # type: ignore
87+
88+
SemanticManifest.validate = lambda _: True # type: ignore
89+
8390

8491
class ManifestHelper:
8592
def __init__(
@@ -456,6 +463,8 @@ def _load_manifest(self) -> Manifest:
456463
register_adapter(runtime_config) # type: ignore
457464

458465
manifest = ManifestLoader.get_full_manifest(runtime_config)
466+
# This adapter doesn't care about semantic models so we clear them out to avoid issues
467+
manifest.semantic_models = {}
459468
reset_adapters()
460469
return manifest
461470

tests/fixtures/dbt/sushi_test/models/schema.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,23 @@ sources:
5252
tables:
5353
- name: items
5454
- name: orders
55+
56+
semantic_models:
57+
- name: top_waiters
58+
description: Some description
59+
model: ref('top_waiters')
60+
measures:
61+
- name: total_waiters
62+
agg: sum
63+
expr: waiter
64+
dimensions:
65+
- name: waiter
66+
type: categorical
67+
68+
metrics:
69+
- name: some_waiter_thing
70+
description: Something
71+
type: simple
72+
label: testing
73+
type_params:
74+
measure: total_waiters

0 commit comments

Comments
 (0)