diff --git a/.changes/unreleased/Fixes-20231016-163953.yaml b/.changes/unreleased/Fixes-20231016-163953.yaml new file mode 100644 index 00000000000..ea21584bee1 --- /dev/null +++ b/.changes/unreleased/Fixes-20231016-163953.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fix partial parsing not working for semantic model change +time: 2023-10-16T16:39:53.05058-07:00 +custom: + Author: ChenyuLInx + Issue: "8859" diff --git a/core/dbt/parser/partial.py b/core/dbt/parser/partial.py index 9c088ec096c..7fcfe48f87d 100644 --- a/core/dbt/parser/partial.py +++ b/core/dbt/parser/partial.py @@ -922,6 +922,9 @@ def delete_schema_semantic_model(self, schema_file, semantic_model_dict): if unique_id in self.saved_manifest.semantic_models: semantic_model = self.saved_manifest.semantic_models[unique_id] if semantic_model.name == semantic_model_name: + # Need to find everything that referenced this semantic model and schedule for parsing + if unique_id in self.saved_manifest.child_map: + self.schedule_nodes_for_parsing(self.saved_manifest.child_map[unique_id]) self.saved_manifest.semantic_models.pop(unique_id) schema_file.semantic_models.remove(unique_id) elif unique_id in self.saved_manifest.disabled: diff --git a/tests/functional/semantic_models/fixtures.py b/tests/functional/semantic_models/fixtures.py index be5d88a7809..8084af09c33 100644 --- a/tests/functional/semantic_models/fixtures.py +++ b/tests/functional/semantic_models/fixtures.py @@ -86,6 +86,39 @@ agg_time_dimension: created_at """ +semantic_model_people_diff_name_yml = """ +version: 2 + +semantic_models: + - name: semantic_people_diff_name + label: "Semantic People" + model: ref('people') + dimensions: + - name: favorite_color + label: "Favorite Color" + type: categorical + - name: created_at + label: "Created At" + type: TIME + type_params: + time_granularity: day + measures: + - name: years_tenure + label: "Years Tenure" + agg: SUM + expr: tenure + - name: people + label: "People" + agg: count + expr: id + entities: + - name: id + label: "Primary ID" + type: primary + defaults: + agg_time_dimension: created_at +""" + semantic_model_descriptions = """ {% docs semantic_model_description %} foo {% enddocs %} {% docs dimension_description %} bar {% enddocs %} diff --git a/tests/functional/semantic_models/test_semantic_models.py b/tests/functional/semantic_models/test_semantic_models.py index 11fdfc32456..945b7fdc04b 100644 --- a/tests/functional/semantic_models/test_semantic_models.py +++ b/tests/functional/semantic_models/test_semantic_models.py @@ -3,11 +3,13 @@ from dbt.contracts.graph.manifest import Manifest from dbt.exceptions import CompilationError from dbt.tests.util import run_dbt +from dbt.tests.util import write_file from tests.functional.semantic_models.fixtures import ( models_people_sql, simple_metricflow_time_spine_sql, semantic_model_people_yml, models_people_metrics_yml, + semantic_model_people_diff_name_yml, semantic_model_people_yml_with_docs, semantic_model_descriptions, ) @@ -71,3 +73,27 @@ def test_unknown_model_raises_issue(self, project): with pytest.raises(CompilationError) as excinfo: run_dbt(["parse"]) assert "depends on a node named 'people' which was not found" in str(excinfo.value) + + +class TestSemanticModelPartialParsing: + @pytest.fixture(scope="class") + def models(self): + return { + "people.sql": models_people_sql, + "metricflow_time_spine.sql": simple_metricflow_time_spine_sql, + "semantic_models.yml": semantic_model_people_yml, + "people_metrics.yml": models_people_metrics_yml, + } + + def test_semantic_model_deleted_partial_parsing(self, project): + # First, use the default saved_queries.yml to define our saved_query, and + # run the dbt parse command + run_dbt(["parse"]) + # Next, modify the default semantic_models.yml to remove the saved query. + write_file( + semantic_model_people_diff_name_yml, + project.project_root, + "models", + "semantic_models.yml", + ) + run_dbt(["compile"])