Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 1.7.latest] Fix partial parsing issue not working for changing semantic model name #8878

Merged
merged 1 commit into from
Oct 25, 2023
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
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20231016-163953.yaml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions core/dbt/parser/partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,9 @@
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])

Check warning on line 927 in core/dbt/parser/partial.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/parser/partial.py#L926-L927

Added lines #L926 - L927 were not covered by tests
self.saved_manifest.semantic_models.pop(unique_id)
schema_file.semantic_models.remove(unique_id)
elif unique_id in self.saved_manifest.disabled:
Expand Down
33 changes: 33 additions & 0 deletions tests/functional/semantic_models/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
26 changes: 26 additions & 0 deletions tests/functional/semantic_models/test_semantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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"])