Skip to content

Commit fa18e0f

Browse files
Change "cumulative input is required" error to be a warning (#412)
Towards #387 ### Description Relaxes the validation error for providing no input to a cumulative metric (no measure nor metric) to be a warning instead of an error to avoid breaking changes. Context: previously, we weren't checking this, so making this an error could break existing manifests that work in general and are being used to run jobs other than this cumulative metric. (The metric will not work in metricflow without an input.) ### Checklist - [x] I have read [the contributing guide](https://github.com/dbt-labs/dbt-semantic-interfaces/blob/main/CONTRIBUTING.md) and understand what's expected of me - [x] I have signed the [CLA](https://docs.getdbt.com/docs/contributor-license-agreements) - [x] This PR includes tests, or tests are not required/relevant for this PR - [x] I have run `changie new` to [create a changelog entry](https://github.com/dbt-labs/dbt-semantic-interfaces/blob/main/CONTRIBUTING.md#adding-a-changelog-entry)
1 parent 004a4ef commit fa18e0f

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Under the Hood
2+
body: Relaxes a validation error for providing no input to a cumulative metric (neither measure nor metric) to be a warning instead of an error to avoid breaking.
3+
time: 2025-09-09T10:24:50.225208-07:00
4+
custom:
5+
Author: theyostalservice
6+
Issue: "387"

dbt_semantic_interfaces/validations/metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _validate_input_measure_xor_metric(cls, metric: Metric) -> Sequence[Validati
8080
)
8181
elif metric.type_params.measure is None and input_metric is None:
8282
issues.append(
83-
ValidationError(
83+
ValidationWarning(
8484
context=MetricContext(
8585
file_context=FileContext.from_metadata(metadata=metric.metadata),
8686
metric=MetricModelReference(metric_name=metric.name),

tests/validations/test_metrics.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ def test_cumulative_metrics() -> None: # noqa: D
11971197

11981198

11991199
@pytest.mark.parametrize(
1200-
"metric, error_substring_if_error",
1200+
"metric, error_substring_if_error, error_substring_if_warning",
12011201
[
12021202
(
12031203
metric_with_guaranteed_meta(
@@ -1209,6 +1209,7 @@ def test_cumulative_metrics() -> None: # noqa: D
12091209
),
12101210
),
12111211
None, # No error; this should pass
1212+
None,
12121213
),
12131214
(
12141215
metric_with_guaranteed_meta(
@@ -1222,6 +1223,7 @@ def test_cumulative_metrics() -> None: # noqa: D
12221223
),
12231224
),
12241225
None, # No error; this should pass
1226+
None,
12251227
),
12261228
(
12271229
metric_with_guaranteed_meta(
@@ -1237,6 +1239,7 @@ def test_cumulative_metrics() -> None: # noqa: D
12371239
),
12381240
"Cumulative metric 'bad_metric_has_both_measure_and_metric_as_inputs' cannot have both a measure "
12391241
"and a metric as inputs. Please remove one of them.",
1242+
None,
12401243
),
12411244
(
12421245
metric_with_guaranteed_meta(
@@ -1246,6 +1249,7 @@ def test_cumulative_metrics() -> None: # noqa: D
12461249
cumulative_type_params=PydanticCumulativeTypeParams(period_agg=PeriodAggregation.FIRST),
12471250
),
12481251
),
1252+
None,
12491253
"Cumulative metric 'bad_metric_has_neither_measure_nor_metric_as_inputs' must have either a measure "
12501254
"or a metric as inputs. Please add one of them.",
12511255
),
@@ -1254,6 +1258,7 @@ def test_cumulative_metrics() -> None: # noqa: D
12541258
def test_cumulative_metrics_have_metric_xor_measure(
12551259
metric: PydanticMetric,
12561260
error_substring_if_error: Optional[str],
1261+
error_substring_if_warning: Optional[str],
12571262
) -> None:
12581263
"""Validate that things like fill_nulls_with and join_to_timespine are not allowed on non-simple metrics."""
12591264
model_validator = SemanticManifestValidator[PydanticSemanticManifest]([CumulativeMetricRule()])
@@ -1294,8 +1299,10 @@ def test_cumulative_metrics_have_metric_xor_measure(
12941299
)
12951300
)
12961301
if error_substring_if_error:
1297-
check_error_in_issues(error_substrings=[error_substring_if_error], issues=validation_results.all_issues)
1298-
else:
1302+
check_error_in_issues(error_substrings=[error_substring_if_error], issues=validation_results.errors)
1303+
if error_substring_if_warning:
1304+
check_error_in_issues(error_substrings=[error_substring_if_warning], issues=validation_results.warnings)
1305+
if not error_substring_if_error and not error_substring_if_warning:
12991306
assert len(validation_results.all_issues) == 0, "expected this metric to pass validation, but it did not"
13001307

13011308

0 commit comments

Comments
 (0)