{"record":{"id":"9d0580f81c89d982","repo":"dbt-labs/dbt-core","slug":"no-execute-var-found-in-state","errorCode":null,"errorMessage":"No execute var found in state","messagePattern":"No execute var found in state","errorType":"exception","errorClass":"minijinja::Error (InvalidOperation)","httpStatus":null,"severity":"error","filePath":"crates/dbt-jinja-vars/src/configured_var.rs","lineNumber":132,"sourceCode":"            Err(Self::missing_var_error(\n                &package_name,\n                &var_name,\n                vars_lookup,\n            ))\n        } else if let Some(execute) = state.lookup(\"execute\", &[]).map(|v| v.is_true()) {\n            if !execute {\n                // if parsing a model and var is missing, return none\n                Ok(Value::from(()))\n            } else {\n                // if compiling a model and var is missing, throw an error\n                Err(Self::missing_var_error(\n                    &package_name,\n                    &var_name,\n                    vars_lookup,\n                ))\n            }\n        } else {\n            Err(Error::new(\n                // TODO: make another error type for this\n                ErrorKind::InvalidOperation,\n                \"No execute var found in state\",\n            ))\n        }\n    }\n}\n\nimpl Object for ConfiguredVar {\n    fn call(\n        self: &Arc<Self>,\n        state: &State<'_, '_>,\n        args: &[Value],\n        listeners: &[Rc<dyn RenderingEventListener>],\n    ) -> Result<Value, Error> {\n        self.call_impl(state, args, listeners)\n    }\n","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-jinja-vars/src/configured_var.rs#L114-L150","documentation":"`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.","triggerScenarios":"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`.","commonSituations":"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.","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."],"exampleFix":"// before\nlet mut state_ctx = Context::new();\n// after\nlet mut state_ctx = Context::new();\nstate_ctx.insert(\"execute\", Value::from(true));\nstate_ctx.insert(\"TARGET_PACKAGE_NAME\", Value::from(\"my_package\"));\n","handlingStrategy":"validation","validationCode":"// pre-check before var evaluation in a custom state\nfn state_ready(ctx: &Context) -> bool {\n    ctx.contains_key(\"execute\") && ctx.contains_key(\"TARGET_PACKAGE_NAME\")\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"No execute var found in state\") => {\n        // rebuild state via the standard dbt context builder, then re-evaluate\n    }\n    other => other,\n}","preventionTips":["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."],"tags":["vars","jinja-context","internal-state"],"backgroundTag":"internal-invariant-violation","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}