Skip to content

Commit

Permalink
Add test around deleting a YAML file containing semantic models and m…
Browse files Browse the repository at this point in the history
…etrics

It was raised in #8860 that an
error is being raised during partial parsing when files containing
metrics/semantic models are deleted. In further testing it looks like this
error specifically happens when a file containing both semantic models and
metrics is deleted. If the deleted file contains just semantic models or
metrics there seems to be no issue. The next commit should contain the fix.
  • Loading branch information
QMalcolm committed Mar 1, 2024
1 parent fc43101 commit ef25e2d
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
54 changes: 54 additions & 0 deletions tests/functional/partial_parsing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,60 @@
agg_time_dimension: created_at
"""

people_sl_yml = """
version: 2
semantic_models:
- name: semantic_people
model: ref('people')
dimensions:
- name: favorite_color
type: categorical
- name: created_at
type: TIME
type_params:
time_granularity: day
measures:
- name: years_tenure
agg: SUM
expr: tenure
- name: people
agg: count
expr: id
entities:
- name: id
type: primary
defaults:
agg_time_dimension: created_at
metrics:
- name: number_of_people
description: Total count of people
label: "Number of people"
type: simple
type_params:
measure: people
meta:
my_meta: 'testing'
- name: collective_tenure
description: Total number of years of team experience
label: "Collective tenure"
type: simple
type_params:
measure:
name: years_tenure
filter: "{{ Dimension('id__loves_dbt') }} is true"
- name: average_tenure
label: Average Tenure
type: ratio
type_params:
numerator: collective_tenure
denominator: number_of_people
"""

env_var_metrics_yml = """
metrics:
Expand Down
31 changes: 30 additions & 1 deletion tests/functional/partial_parsing/test_pp_metrics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest

from dbt.tests.util import run_dbt, write_file, get_manifest
from dbt.cli.main import dbtRunner
from dbt.contracts.graph.manifest import Manifest
from dbt.tests.util import run_dbt, rm_file, write_file, get_manifest
from tests.functional.partial_parsing.fixtures import (
people_sql,
metricflow_time_spine_sql,
Expand All @@ -9,6 +11,7 @@
people_metrics2_yml,
metric_model_a_sql,
people_metrics3_yml,
people_sl_yml,
)

from dbt.exceptions import CompilationError
Expand Down Expand Up @@ -84,3 +87,29 @@ def test_metrics(self, project):
# We use "parse" here and not "run" because we're checking that the CompilationError
# occurs at parse time, not compilation
results = run_dbt(["parse"])


class TestDeleteFileWithMetricsAndSemanticModels:
@pytest.fixture(scope="class")
def models(self):
return {
"people.sql": people_sql,
"metricflow_time_spine.sql": metricflow_time_spine_sql,
"people_sl.yml": people_sl_yml,
}

def test_metrics(self, project):
# Initial parsing
runner = dbtRunner()
result = runner.invoke(["parse"])
assert result.success
manifest = result.result
assert isinstance(manifest, Manifest)
assert len(manifest.metrics) == 3

# Remove metric file
rm_file(project.project_root, "models", "people_sl.yml")

# Rerun parse, shouldn't fail
result = runner.invoke(["parse"])
assert result.exception is None, result.exception

0 comments on commit ef25e2d

Please sign in to comment.