dbt-labs/dbt-core · error · minijinja::Error (InvalidOperation)

has_var requires 1 argument

Error message

has_var requires 1 argument

What it means

The `has_var()` Jinja method checks whether a named var exists in the configuration. It requires exactly one argument; `call_has_var` rejects a call with an empty argument list with this error. (Extra arguments beyond the first are not rejected here, but zero arguments always is.)

Source

Thrown at crates/dbt-jinja-vars/src/var.rs:115

    fn missing_var_error<M>(package_name: &str, var_name: &str, vars_lookup: &M) -> Error
    where
        M: Serialize + ?Sized,
    {
        Error::new(
            ErrorKind::InvalidOperation,
            format!(
                "Required var '{}' not found in config:\nVars supplied to {} = {}",
                var_name,
                package_name,
                serde_json::to_string_pretty(vars_lookup).unwrap()
            ),
        )
    }

    /// Common handler for `has_var`.
    fn call_has_var(&self, state: &State<'_, '_>, args: &[Value]) -> Result<Value, Error> {
        if args.is_empty() {
            return Err(Error::new(
                ErrorKind::InvalidOperation,
                "has_var requires 1 argument",
            ));
        }
        let var_name = args[0].as_str().ok_or_else(|| {
            Error::new(
                ErrorKind::InvalidOperation,
                "argument 'name' to has_var() has incompatible type; value is not a string",
            )
        })?;
        let present = self.contains_var(state, var_name)?;
        Ok(Value::from(present))
    }

    /// Common implementation for `Object::call`.
    fn call_impl(
        self: &Arc<Self>,
        state: &State<'_, '_>,

View on GitHub (pinned to 0267ce9170)

Solutions

  1. Pass the var name: `{{ has_var('my_var') }}`.
  2. If checking existence per-package, ensure your caller passes the resolved name string as the single argument.
  3. Review the call site for an accidentally deleted or commented-out argument.

Example fix

// before (Jinja)
{% if has_var() %}
// after
{% if has_var('my_var') %}
Defensive patterns

Strategy: validation

Validate before calling

{% if not name %}{{ exceptions.raise_compiler_error('has_var requires a name') }}{% endif %}

Prevention

When it happens

Trigger: Calling `{{ has_var() }}` with no arguments — e.g. forgetting the name entirely, or intending a zero-argument existence probe of all vars.

Common situations: Typos that drop the argument (`has_var('x',)` still passes args, but `has_var()` doesn't); misunderstanding `has_var` as taking a dict or package argument; copy-paste removal of the argument during refactoring.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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