Skip to content

Commit

Permalink
Add the SemanticModel of a Metric's measure property to the `Metr…
Browse files Browse the repository at this point in the history
…ic`'s `depends_on`
  • Loading branch information
QMalcolm committed Jul 1, 2023
1 parent 60864b1 commit a8f3ffd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ def _process_metric_node(
current_project: str,
metric: Metric,
) -> None:
"""Sets a metric's input_measures"""
"""Sets a metric's `input_measures` and `depends_on` properties"""

# This ensures that if this metrics input_measures have already been set
# we skip the work. This could happen either due to recursion or if multiple
Expand All @@ -1459,6 +1459,18 @@ def _process_metric_node(
metric.type_params.measure is not None
), f"{metric} should have a measure defined, but it does not."
metric.type_params.input_measures.append(metric.type_params.measure)
target_semantic_model = manifest.resolve_semantic_model_for_measure(
target_measure_name=metric.type_params.measure.name,
current_project=current_project,
node_package=metric.package_name,
)
if target_semantic_model is None:
raise dbt.exceptions.ParsingError(
f"A semantic model having a measure `{metric.type_params.measure.name}` does not exist but was referenced.",
node=metric,
)

metric.depends_on.add_node(target_semantic_model.unique_id)

elif metric.type is MetricType.DERIVED or metric.type is MetricType.RATIO:
input_metrics = metric.input_metrics
Expand Down

0 comments on commit a8f3ffd

Please sign in to comment.