diff --git a/.changes/unreleased/Fixes-20240212-154728.yaml b/.changes/unreleased/Fixes-20240212-154728.yaml new file mode 100644 index 00000000000..6e8c070764f --- /dev/null +++ b/.changes/unreleased/Fixes-20240212-154728.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fix Semantic Model Compare node relations +time: 2024-02-12T15:47:28.752107-08:00 +custom: + Author: ChenyuLInx + Issue: "9548" diff --git a/core/dbt/contracts/graph/nodes.py b/core/dbt/contracts/graph/nodes.py index cb032a953d8..1f08f310f17 100644 --- a/core/dbt/contracts/graph/nodes.py +++ b/core/dbt/contracts/graph/nodes.py @@ -1527,9 +1527,6 @@ def depends_on_macros(self): def same_model(self, old: "SemanticModel") -> bool: return self.model == old.model - def same_node_relation(self, old: "SemanticModel") -> bool: - return self.node_relation == old.node_relation - def same_description(self, old: "SemanticModel") -> bool: return self.description == old.description @@ -1562,7 +1559,6 @@ def same_contents(self, old: Optional["SemanticModel"]) -> bool: return ( self.same_model(old) - and self.same_node_relation(old) and self.same_description(old) and self.same_defaults(old) and self.same_entities(old) diff --git a/tests/unit/test_semantic_models.py b/tests/unit/test_semantic_models.py index 7ba1bd9c6a1..3bd79a679e9 100644 --- a/tests/unit/test_semantic_models.py +++ b/tests/unit/test_semantic_models.py @@ -4,6 +4,7 @@ from dbt.artifacts.resources import Dimension, Entity, Measure, Defaults from dbt.contracts.graph.nodes import SemanticModel +from dbt.artifacts.resources.v1.semantic_model import NodeRelation from dbt.node_types import NodeType from dbt_semantic_interfaces.references import MeasureReference from dbt_semantic_interfaces.type_enums import AggregationType, DimensionType, EntityType @@ -41,7 +42,9 @@ def default_semantic_model( dimensions=dimensions, entities=entities, measures=measures, - node_relation=None, + node_relation=NodeRelation( + alias="test_alias", schema_name="test_schema", database="test_database" + ), ) @@ -92,3 +95,12 @@ def test_semantic_model_same_contents_update_model(default_semantic_model: Seman default_semantic_model_copy.model = "ref('test_another_model')" assert not default_semantic_model.same_contents(default_semantic_model_copy) + + +def test_semantic_model_same_contents_different_node_relation( + default_semantic_model: SemanticModel, +): + default_semantic_model_copy = deepcopy(default_semantic_model) + default_semantic_model_copy.node_relation.alias = "test_another_alias" + # Relation should not be consided in same_contents + assert default_semantic_model.same_contents(default_semantic_model_copy)