Skip to content

Commit e1daafd

Browse files
committed
create and use canonical_name for TestConfig
1 parent eb01334 commit e1daafd

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

sqlmesh/dbt/basemodel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def sqlmesh_model_kwargs(
305305
jinja_macros.add_globals(self._model_jinja_context(model_context, dependencies))
306306

307307
model_kwargs = {
308-
"audits": [(test.name, {}) for test in self.tests],
308+
"audits": [(test.canonical_name, {}) for test in self.tests],
309309
"column_descriptions": column_descriptions_to_sqlmesh(self.columns) or None,
310310
"depends_on": {
311311
model.canonical_name(context) for model in model_context.refs.values()

sqlmesh/dbt/loader.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ def _load_audits(
172172
for test in package.tests.values():
173173
logger.debug("Converting '%s' to sqlmesh format", test.name)
174174
try:
175-
audit = test.to_sqlmesh(package_context)
176-
audits[audit.name] = audit
175+
audits[test.canonical_name] = test.to_sqlmesh(package_context)
177176

178177
except BaseMissingReferenceError as e:
179178
ref_type = "model" if isinstance(e, MissingModelError) else "source"

sqlmesh/dbt/test.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ def _validate_severity(cls, v: t.Union[Severity, str]) -> Severity:
109109
def _lowercase_name(cls, v: str) -> str:
110110
return v.lower()
111111

112+
@property
113+
def canonical_name(self) -> str:
114+
return f"{self.package_name}.{self.name}" if self.package_name else self.name
115+
112116
@property
113117
def is_standalone(self) -> bool:
114118
# A test is standalone if:
@@ -154,14 +158,11 @@ def to_sqlmesh(self, context: DbtContext) -> Audit:
154158
blocking = self.severity == Severity.ERROR
155159

156160
audit: Audit
157-
audit_name = self.name
158-
if self.package_name and self.package_name != context.project_name:
159-
audit_name = f"{self.package_name}.{self.name}"
160161

161162
if self.is_standalone:
162163
jinja_macros.add_globals({"this": self.relation_info})
163164
audit = StandaloneAudit(
164-
name=audit_name,
165+
name=self.name,
165166
dbt_node_info=self.node_info,
166167
dialect=self.dialect(context),
167168
skip=skip,
@@ -178,7 +179,7 @@ def to_sqlmesh(self, context: DbtContext) -> Audit:
178179
)
179180
else:
180181
audit = ModelAudit(
181-
name=audit_name,
182+
name=self.name,
182183
dbt_node_info=self.node_info,
183184
dialect=self.dialect(context),
184185
skip=skip,

tests/dbt/test_model.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,23 +190,23 @@ def test_manifest_filters_standalone_tests_from_models(
190190
# Should only have "not_null" test, not the "relationships" test
191191
model1_audit_names = [audit[0] for audit in model1_snapshot.model.audits]
192192
assert len(model1_audit_names) == 1
193-
assert model1_audit_names[0] == "not_null_model1_id"
193+
assert model1_audit_names[0] == "local.not_null_model1_id"
194194

195195
# Verify model2 has its non-standalone test
196196
model2_audit_names = [audit[0] for audit in model2_snapshot.model.audits]
197197
assert len(model2_audit_names) == 1
198-
assert model2_audit_names[0] == "not_null_model2_id"
198+
assert model2_audit_names[0] == "local.not_null_model2_id"
199199

200200
# Verify the standalone test (relationships) exists as a StandaloneAudit
201201
all_non_standalone_audits = [name for name in context._audits]
202202
assert sorted(all_non_standalone_audits) == [
203-
"not_null_model1_id",
204-
"not_null_model2_id",
203+
"local.not_null_model1_id",
204+
"local.not_null_model2_id",
205205
]
206206

207207
standalone_audits = [name for name in context._standalone_audits]
208208
assert len(standalone_audits) == 1
209-
assert standalone_audits[0] == "relationships_model1_id__id__ref_model2_"
209+
assert standalone_audits[0] == "local.relationships_model1_id__id__ref_model2_"
210210

211211
plan_builder = context.plan_builder()
212212
dag = plan_builder._build_dag()

0 commit comments

Comments
 (0)