Skip to content

Commit

Permalink
Fix: SemanticModel.same_model compares model attribute (#9549)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk authored Feb 10, 2024
1 parent f732b76 commit c12f6fb
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240209-170146.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: only include unmodified semantic mdodels in state:modified selection
time: 2024-02-09T17:01:46.676097-05:00
custom:
Author: michelleark
Issue: "9548"
2 changes: 1 addition & 1 deletion core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,7 @@ def depends_on_macros(self):
return self.depends_on.macros

def same_model(self, old: "SemanticModel") -> bool:
return self.model == old.same_model
return self.model == old.model

def same_node_relation(self, old: "SemanticModel") -> bool:
return self.node_relation == old.node_relation
Expand Down
38 changes: 38 additions & 0 deletions tests/functional/defer_state/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,40 @@
{% endsnapshot %}
"""


semantic_model_schema_yml = """
models:
- name: view_model
columns:
- name: id
data_tests:
- unique:
severity: error
- not_null
- name: name
semantic_models:
- name: my_sm
model: ref('view_model')
"""

modified_semantic_model_schema_yml = """
models:
- name: view_model
columns:
- name: id
data_tests:
- unique:
severity: error
- not_null
- name: name
semantic_models:
- name: my_sm
model: ref('view_model')
description: modified description
"""

model_1_sql = """
select * from {{ ref('seed') }}
"""
Expand Down Expand Up @@ -422,3 +456,7 @@
config:
group: finance
"""

metricflow_time_spine_sql = """
SELECT to_date('02/20/2023', 'mm/dd/yyyy') as date_day
"""
22 changes: 22 additions & 0 deletions tests/functional/defer_state/test_modified_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
table_model_now_view_sql,
table_model_now_incremental_sql,
view_model_now_table_sql,
metricflow_time_spine_sql,
semantic_model_schema_yml,
modified_semantic_model_schema_yml,
)


Expand Down Expand Up @@ -993,3 +996,22 @@ def test_changed_access(self, project):

results = run_dbt(["list", "-s", "state:modified", "--state", "./state"])
assert results == ["test.table_model.v1", "test.table_model.v2"]


class TestChangedSemanticModelContents(BaseModifiedState):
@pytest.fixture(scope="class")
def models(self):
return {
"view_model.sql": view_model_sql,
"schema.yml": semantic_model_schema_yml,
"metricflow_time_spine.sql": metricflow_time_spine_sql,
}

def test_changed_semantic_model_contents(self, project):
self.run_and_save_state()
results = run_dbt(["list", "-s", "state:modified", "--state", "./state"])
assert len(results) == 0

write_file(modified_semantic_model_schema_yml, "models", "schema.yml")
results = run_dbt(["list", "-s", "state:modified", "--state", "./state"])
assert len(results) == 1
15 changes: 14 additions & 1 deletion tests/unit/test_semantic_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from copy import deepcopy
import pytest

from typing import List

from dbt.artifacts.resources import Dimension, Entity, Measure, Defaults
Expand Down Expand Up @@ -79,3 +79,16 @@ def test_checked_agg_time_dimension_for_measure_exception(default_semantic_model
f"Aggregation time dimension for measure {measure.name} on semantic model {default_semantic_model.name}"
in str(execinfo.value)
)


def test_semantic_model_same_contents(default_semantic_model: SemanticModel):
default_semantic_model_copy = deepcopy(default_semantic_model)

assert default_semantic_model.same_contents(default_semantic_model_copy)


def test_semantic_model_same_contents_update_model(default_semantic_model: SemanticModel):
default_semantic_model_copy = deepcopy(default_semantic_model)
default_semantic_model_copy.model = "ref('test_another_model')"

assert not default_semantic_model.same_contents(default_semantic_model_copy)

0 comments on commit c12f6fb

Please sign in to comment.