Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sqlmesh/dbt/basemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def sqlmesh_model_kwargs(
jinja_macros.add_globals(self._model_jinja_context(model_context, dependencies))

model_kwargs = {
"audits": [(test.name, {}) for test in self.tests],
"audits": [(test.canonical_name, {}) for test in self.tests],
"column_descriptions": column_descriptions_to_sqlmesh(self.columns) or None,
"depends_on": {
model.canonical_name(context) for model in model_context.refs.values()
Expand Down
3 changes: 2 additions & 1 deletion sqlmesh/dbt/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ def _load_audits(
for test in package.tests.values():
logger.debug("Converting '%s' to sqlmesh format", test.name)
try:
audits[test.name] = test.to_sqlmesh(package_context)
audits[test.canonical_name] = test.to_sqlmesh(package_context)

except BaseMissingReferenceError as e:
ref_type = "model" if isinstance(e, MissingModelError) else "source"
logger.warning(
Expand Down
4 changes: 4 additions & 0 deletions sqlmesh/dbt/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ def _validate_severity(cls, v: t.Union[Severity, str]) -> Severity:
def _lowercase_name(cls, v: str) -> str:
return v.lower()

@property
def canonical_name(self) -> str:
return f"{self.package_name}.{self.name}" if self.package_name else self.name

@property
def is_standalone(self) -> bool:
# A test is standalone if:
Expand Down
2 changes: 1 addition & 1 deletion tests/core/integration/test_dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_dbt_is_incremental_table_is_missing(sushi_test_dbt_context: Context):
model = context.get_model("sushi.waiter_revenue_by_day_v2")
model = model.copy(update={"kind": IncrementalUnmanagedKind(), "start": "2023-01-01"})
context.upsert_model(model)
context._standalone_audits["test_top_waiters"].start = "2023-01-01"
context._standalone_audits["sushi.test_top_waiters"].start = "2023-01-01"

context.plan("prod", auto_apply=True, no_prompts=True, skip_tests=True)

Expand Down
10 changes: 5 additions & 5 deletions tests/dbt/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,23 +190,23 @@ def test_manifest_filters_standalone_tests_from_models(
# Should only have "not_null" test, not the "relationships" test
model1_audit_names = [audit[0] for audit in model1_snapshot.model.audits]
assert len(model1_audit_names) == 1
assert model1_audit_names[0] == "not_null_model1_id"
assert model1_audit_names[0] == "local.not_null_model1_id"

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

# Verify the standalone test (relationships) exists as a StandaloneAudit
all_non_standalone_audits = [name for name in context._audits]
assert sorted(all_non_standalone_audits) == [
"not_null_model1_id",
"not_null_model2_id",
"local.not_null_model1_id",
"local.not_null_model2_id",
]

standalone_audits = [name for name in context._standalone_audits]
assert len(standalone_audits) == 1
assert standalone_audits[0] == "relationships_model1_id__id__ref_model2_"
assert standalone_audits[0] == "local.relationships_model1_id__id__ref_model2_"

plan_builder = context.plan_builder()
dag = plan_builder._build_dag()
Expand Down