dbt-labs/dbt-core · error · minijinja::Error (InvalidOperation)
No execute var found in state
Error message
No execute var found in state
What it means
`ConfiguredVar::call_as_function` falls back to checking an `execute` variable in the Jinja state when the primary var lookup paths don't apply. This error is thrown when even that `execute` key is missing from the state, leaving the function with no way to decide execution-mode behavior. The TODO in the source acknowledges this should get a dedicated error kind — it's effectively an internal context invariant.
Source
Thrown at crates/dbt-jinja-vars/src/configured_var.rs:132
Err(Self::missing_var_error(
&package_name,
&var_name,
vars_lookup,
))
} else if let Some(execute) = state.lookup("execute", &[]).map(|v| v.is_true()) {
if !execute {
// if parsing a model and var is missing, return none
Ok(Value::from(()))
} else {
// if compiling a model and var is missing, throw an error
Err(Self::missing_var_error(
&package_name,
&var_name,
vars_lookup,
))
}
} else {
Err(Error::new(
// TODO: make another error type for this
ErrorKind::InvalidOperation,
"No execute var found in state",
))
}
}
}
impl Object for ConfiguredVar {
fn call(
self: &Arc<Self>,
state: &State<'_, '_>,
args: &[Value],
listeners: &[Rc<dyn RenderingEventListener>],
) -> Result<Value, Error> {
self.call_impl(state, args, listeners)
}
View on GitHub (pinned to 0267ce9170)
Solutions
- Set `execute` in the evaluation context/state before calling var().
- Ensure you're evaluating through the standard dbt context builders rather than a hand-rolled state.
- In tests, seed the state with `execute` (typically true or false as appropriate) alongside TARGET_PACKAGE_NAME.
Example fix
// before
let mut state_ctx = Context::new();
// after
let mut state_ctx = Context::new();
state_ctx.insert("execute", Value::from(true));
state_ctx.insert("TARGET_PACKAGE_NAME", Value::from("my_package"));
Defensive patterns
Strategy: validation
Validate before calling
// pre-check before var evaluation in a custom state
fn state_ready(ctx: &Context) -> bool {
ctx.contains_key("execute") && ctx.contains_key("TARGET_PACKAGE_NAME")
} Try / catch
match result {
Err(e) if e.to_string().contains("No execute var found in state") => {
// rebuild state via the standard dbt context builder, then re-evaluate
}
other => other,
} Prevention
- Seed the state with `execute` and TARGET_PACKAGE_NAME before evaluation.
- Use standard dbt context builders rather than hand-rolled states.
- In tests, assert the context contains the required keys before rendering.
When it happens
Trigger: Evaluating `var()` in a Minijinja state that lacks both package vars context and the `execute` binding — e.g. a bare state used by tests, ad-hoc rendering tools, or a phase that forgot to set `execute`.
Common situations: Custom tooling rendering macros with a minimal context; parse-phase evaluation before the execute flag is set; unit tests constructing State without standard dbt bindings.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- 'TARGET_PACKAGE_NAME' should be set. Missing in configured v
- Package vars should be initialized for package: {package_nam
- Missing default value for var in dbt_project.yml: {var_name}
- Method {method} not found
AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07).
Data as JSON: /api/errors/9d0580f81c89d982.
Report an issue: GitHub.