dbt-labs/dbt-core · error

query ctx

Error message

query ctx

What it means

Test-only assertion in project_model_and_run_id_are_read_for_usage_attribution: constructing the query context from a DbtModel must succeed so the test can assert that project/model name and invocation id are picked up for dbt-compute usage attribution. Fires only if QueryCtx construction from a model regresses.

Solutions

  1. Fix the underlying QueryCtx construction failure revealed by this test
  2. Run the test with output to see the actual construction error
  3. Treat failure here as a regression in usage-attribution context building, not a runtime user error
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/dbt-adapter/src/query_ctx.rs:202 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at crates/dbt-adapter/src/query_ctx.rs:202

        });
    }

    /// dbt-compute usage attribution reads project/model name off the node and the
    /// invocation id off the Jinja `invocation_id` global, the same key the BigQuery
    /// job-label path already reads.
    #[test]
    fn project_model_and_run_id_are_read_for_usage_attribution() {
        let mut model = DbtModel::default();
        model.__common_attr__.unique_id = "model.analytics.customer_orders_summary".to_string();
        model.__common_attr__.name = "customer_orders_summary".to_string();
        model.__common_attr__.package_name = "analytics".to_string();
        let yaml_model = dbt_yaml::to_value(&model).expect("model yaml");

        let mut ctx: BTreeMap<String, Value> = BTreeMap::new();
        ctx.insert("model".to_string(), Value::from_serialize(&yaml_model));
        ctx.insert("invocation_id".to_string(), Value::from("run-42"));
        with_state(ctx, |state| {
            let query_ctx = query_ctx_from_state(state).expect("query ctx");
            assert_eq!(
                query_ctx.project_name().map(String::as_str),
                Some("analytics")
            );
            assert_eq!(
                query_ctx.model_name().map(String::as_str),
                Some("customer_orders_summary")
            );
            assert_eq!(query_ctx.run_id().map(String::as_str), Some("run-42"));
        });
    }
}

View on GitHub (pinned to 0267ce9170)