dbt-labs/dbt-core · error · InvalidOperation

diff_of_two_dicts requires a dict_a argument

Error message

diff_of_two_dicts requires a dict_a argument

What it means

diff_of_two_dicts validates that a value for dict_a is available, either via the dict_a kwarg or the first positional argument. When neither is present the function throws this InvalidOperation error. It is a required-argument check distinct from the arity check.

Source

Thrown at crates/dbt-jinja-utils/src/functions/base.rs:614

    }
}

/// A function that returns the difference between two dictionaries
/// Not documented in dbt Jinja docs, but included in base.py
pub fn diff_of_two_dicts_fn() -> impl Fn(&[Value], Kwargs) -> Result<Value, Error> {
    move |args: &[Value], kwargs: Kwargs| -> Result<Value, Error> {
        if args.len() != 2 {
            return Err(Error::new(
                ErrorKind::InvalidOperation,
                "diff_of_two_dicts requires exactly 2 arguments",
            ));
        }

        let dict_a_arg = match (kwargs.get("dict_a"), args.first()) {
            (Ok(value), _) => value,
            (_, Some(value)) => value,
            _ => {
                return Err(Error::new(
                    ErrorKind::InvalidOperation,
                    "diff_of_two_dicts requires a dict_a argument",
                ));
            }
        }
        .clone();

        let dict_b_arg = match (kwargs.get("dict_b"), args.get(1)) {
            (Ok(value), _) => value,
            (_, Some(value)) => value,
            _ => {
                return Err(Error::new(
                    ErrorKind::InvalidOperation,
                    "diff_of_two_dicts requires a dict_b argument",
                ));
            }
        }
        .clone();

View on GitHub (pinned to 0267ce9170)

Solutions

  1. Provide the first dict positionally: diff_of_two_dicts(a, b)
  2. Or pass it explicitly: diff_of_two_dicts(dict_a=a, dict_b=b)
  3. Check that the variable holding dict_a is defined and not undefined at render time

Example fix

// before
{% set diff = diff_of_two_dicts(dict_b=other) %}
// after
{% set diff = diff_of_two_dicts(dict_a=my_dict, dict_b=other) %}
Defensive patterns

Strategy: validation

Validate before calling

{% if dict_a is not defined %}
  {{ exceptions.raise_compiler_error('dict_a is required before diff_of_two_dicts in ' ~ this) }}
{% endif %}

Type guard

{% macro is_dict(x) %}{{ return(x is defined and x is mapping) }}{% endmacro %}

Prevention

When it happens

Trigger: Calling diff_of_two_dicts() with zero positional args and no dict_a kwarg, or calling it with only dict_b=... supplied. Notably this fires with 2+ args only if lookup order breaks, but practically it fires on the missing-dict_a call shape.

Common situations: Kwargs/positional mixing mistakes: developers pass dict_b= keyword only and forget dict_a; templates built programmatically where the first positional slot ends up empty.

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/608416e6c37e8661. Report an issue: GitHub.