dbt-labs/dbt-core · error
events_last_year should compile without error
Error message
events_last_year should compile without error
What it means
Test-only panic: compiling an `events_last_year` time-offset metric spec for DuckDB failed, tripping `.expect("events_last_year should compile without error")`. The test additionally requires the generated SQL to contain an INTERVAL expression, so this specific case guards 1-year offset SQL generation.
Source
Thrown at crates/dbt-metricflow/src/lib.rs:11294
}],
));
let spec = SemanticQuerySpec {
metrics: vec!["events_last_year".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("events_last_year should compile without error");
assert!(
sql.contains("INTERVAL"),
"SQL must contain an INTERVAL expression for the 1-year offset\n SQL:\n{sql}"
);
assert!(
sql.contains("INNER JOIN"),
"offset CTE must use an INNER JOIN to apply the time shift\n SQL:\n{sql}"
);
}
#[test]
fn test_filter_on_outer_derived_metric_propagates_to_inputs() {
let mut store = MockStore::new();
store.metrics.push(RawMetricRow {
name: "count_nps".into(),
metric_type: "simple".into(),View on GitHub (pinned to 0267ce9170)
Solutions
- Read the underlying compile Err / assert message for the missing piece
- Ensure the metric has a valid primary time dimension and the offset (1 year) is supported
- Check the DuckDB SQL renderer for INTERVAL emission on time offsets
- Update the compiler change that regressed offset metric SQL
Example fix
null
Defensive patterns
Strategy: try-catch
Validate before calling
// ensure required time params before compile assert!(spec.metric.is_some(), "spec must target events_last_year metric"); assert!(spec.apply_group_by, "group_by required for offset metrics");
Try / catch
let sql = compile(&mut store, &spec, Dialect::DuckDB)
.unwrap_or_else(|e| panic!("events_last_year compile failed: {e:?}")); Prevention
- Provide a primary time dimension for offset metrics
- Verify DuckDB dialect renders INTERVAL for year offsets
- Add assert coverage for offset SQL after refactors
When it happens
Trigger: `compile` returns Err for the events_last_year spec (missing metric aggregation params, unsupported time offset, or grain/time-spine issues), or the compiled SQL lacks INTERVAL which a later assert catches.
Common situations: Regressions in time-offset metric compilation; DuckDB dialect losing INTERVAL rendering for year offsets; metric store missing required time dimension or time spine config.
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
- yoy_growth should compile without error
- new-style cumulative metric should compile without error
- clean_sql
- invalid return value
- Compilation Error for {} from {}: {}
AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07).
Data as JSON: /api/errors/b73fbee3c5759051.
Report an issue: GitHub.