dbt-labs/dbt-core · error

yoy_growth should compile without error

Error message

yoy_growth should compile without error

What it means

A test-only panic in dbt-metricflow's test-suite: `compile(&mut store, &spec, Dialect::DuckDB)` failed to compile a year-over-year growth metric spec, so `.expect("yoy_growth should compile without error")` panics. It indicates the semantic layer compiler rejected a metric the test considers valid — a regression in cumulative/growth metric compilation.

Source

Thrown at crates/dbt-metricflow/src/lib.rs:11212

            }],
        ));

        let spec = SemanticQuerySpec {
            metrics: vec!["yoy_growth".into()],
            group_by: vec![GroupBySpec::TimeDimension {
                name: "metric_time".into(),
                granularity: "month".into(),
                date_part: None,
            }],
            where_filters: vec![],
            order_by: vec![],
            limit: None,
            time_constraint: None,
            apply_group_by: true,
        };

        let sql = compile(&mut store, &spec, Dialect::DuckDB)
            .expect("yoy_growth should compile without error");

        let cte_defs = sql.matches("base_last_year AS (").count();
        assert_eq!(
            cte_defs, 1,
            "CTE 'base_last_year' must be defined exactly once\n  SQL:\n{sql}"
        );
    }

    #[test]
    fn test_offset_window_object_format_is_applied() {
        let mut store = MockStore::new();

        store.metrics.push(RawMetricRow {
            name: "events".into(),
            metric_type: "simple".into(),
            description: String::new(),
            type_params: r#"{
                "metric_aggregation_params": {

View on GitHub (pinned to 0267ce9170)

Solutions

  1. Inspect the Err from `compile` (it names the missing aggregation params or spec field)
  2. Verify the metric spec includes the required time-offset/growth parameters
  3. Update or revert the metricflow change that altered cumulative metric base construction
  4. Re-run the test after fixing the compiler to confirm CTE base_last_year appears exactly once

Example fix

// before
let sql = compile(&mut store, &spec, Dialect::DuckDB).expect("yoy_growth should compile without error");
// after
let sql = compile(&mut store, &spec, Dialect::DuckDB).unwrap_or_else(|e| panic!("yoy_growth compile failed: {e:?}"));
Defensive patterns

Strategy: try-catch

Validate before calling

// validate spec before compiling
assert!(spec.metric.is_some(), "spec must reference a metric");
assert!(spec.apply_group_by, "group_by must be applied for growth metrics");

Try / catch

let sql = compile(&mut store, &spec, Dialect::DuckDB)
    .unwrap_or_else(|e| panic!("yoy_growth compile failed: {e:?}"));

Prevention

When it happens

Trigger: Building a `MetricInput`-driven query spec with `apply_group_by: true` against a metric store where the yoy_growth metric's calc/offset parameters are missing or misparsed, so the DuckDB compile returns Err.

Common situations: Changes to cumulative/derived metric aggregation-param handling breaking time-offset metrics; DuckDB-specific SQL generation regressions; metric definitions missing `time_offset`/growth params.

Understand the failure class

Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.

Related errors


AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07). Data as JSON: /api/errors/8506dde2b83098ff. Report an issue: GitHub.