{"record":{"id":"7f745431a6d4abac","repo":"dbt-labs/dbt-core","slug":"target-package-name-should-be-set-missing-in-co","errorCode":null,"errorMessage":"'TARGET_PACKAGE_NAME' should be set. Missing in configured var context while looking up var: {var_name}","messagePattern":"'TARGET_PACKAGE_NAME' should be set\\. Missing in configured var context while looking up var: (.+?)","errorType":"exception","errorClass":"minijinja::Error (InvalidOperation)","httpStatus":null,"severity":"error","filePath":"crates/dbt-jinja-vars/src/configured_var.rs","lineNumber":56,"sourceCode":"\n    /// Returns a copy whose package namespace does not depend on a Jinja context key.\n    pub fn bind_package(&self, package_name: impl Into<String>) -> Self {\n        Self {\n            package_name: Some(package_name.into()),\n            ..self.clone()\n        }\n    }\n\n    fn package_name(&self, state: &State<'_, '_>, var_name: &str) -> Result<String, Error> {\n        self.package_name\n            .clone()\n            .or_else(|| {\n                state\n                    .lookup(TARGET_PACKAGE_NAME, &[])\n                    .and_then(|value| value.as_str().map(str::to_string))\n            })\n            .ok_or_else(|| {\n                Error::new(\n                    ErrorKind::InvalidOperation,\n                    format!(\n                        \"'TARGET_PACKAGE_NAME' should be set. Missing in configured var context while looking up var: {var_name}\"\n                    ),\n                )\n            })\n    }\n}\n\nimpl VarFunction for ConfiguredVar {\n    fn contains_var(&self, state: &State<'_, '_>, var_name: &str) -> Result<bool, Error> {\n        let package_name = self.package_name(state, var_name)?;\n        let vars_lookup = self.vars.get(&package_name).ok_or_else(|| {\n            Error::new(\n                ErrorKind::InvalidOperation,\n                format!(\"Package vars should be initialized for package: {package_name}\"),\n            )\n        })?;","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-jinja-vars/src/configured_var.rs#L38-L74","documentation":"`ConfiguredVar::package_name` resolves the current package name from the Jinja state via a `TARGET_PACKAGE_NAME` lookup to scope `var()` resolution. This error is thrown when that key is absent from the configured var context while a var lookup is in progress, so the var cannot be attributed to a package. It signals that the var evaluation context was not fully populated by the caller.","triggerScenarios":"Calling `var('my_var')` (or `contains_var`/`call_as_function`, which both route through `package_name`) during a phase where the context lacks TARGET_PACKAGE_NAME — e.g. parsing dbt_project.yml, custom `var` evaluation outside a node context, or a partially built state.","commonSituations":"Evaluating vars in a bare Minijinja state during tests or tools; invoking var() during dbt_project.yml parsing without a package-scoped context; custom integrations that build the context without setting TARGET_PACKAGE_NAME.","solutions":["Ensure the evaluation context sets `TARGET_PACKAGE_NAME` (the package the var lookup belongs to) before calling var().","If evaluating during dbt_project.yml parsing, use the code path that supplies a default or the special `dbt_project.yml` package name.","Check upstream code that constructs the var context and add the TARGET_PACKAGE_NAME binding."],"exampleFix":"// before\nlet ctx = Context::new(); // TARGET_PACKAGE_NAME missing\n// after\nlet ctx = Context::from([(\"TARGET_PACKAGE_NAME\", Value::from(\"my_package\"))]);\n","handlingStrategy":"validation","validationCode":"// Rust caller pre-check before var evaluation\nfn context_has_package_name(ctx: &dyn StringValue) -> bool { /* state.lookup(\"TARGET_PACKAGE_NAME\").is_some() */ }","typeGuard":null,"tryCatchPattern":"match configured.contains_var(state, var_name) {\n    Err(e) if e.to_string().contains(\"TARGET_PACKAGE_NAME\") => {\n        // rebuild context with TARGET_PACKAGE_NAME set, then retry once\n    }\n    other => other,\n}","preventionTips":["Always set TARGET_PACKAGE_NAME in var-evaluation contexts.","Use standard dbt context builders instead of hand-built states.","Avoid evaluating var() during dbt_project.yml parsing without a default."],"tags":["vars","jinja-context","configuration"],"backgroundTag":"missing-config-value","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}