dbt-labs/dbt-core · error · InvalidOperation

set_strict requires exactly 1 argument

Error message

set_strict requires exactly 1 argument

What it means

set_strict() is a strict variant of set() that deduplicates an iterable, failing hard rather than coercing. It accepts exactly one positional argument; any other count throws this InvalidOperation error before the value is examined.

Source

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

        Ok(Value::from(rendered))
    }
}

/// Strict version of set() that fails if the input is not iterable.
///
/// Args:
///     value: An iterable value to convert to a set
///
/// Example:
/// ```jinja
/// {% set my_list = [1, 2, 2, 3] %}
/// {% set unique_values = set_strict(my_list) %}
/// -- Returns [1, 2, 3] or fails if my_list is not iterable
/// ```
pub fn set_strict_fn() -> impl Fn(&[Value], Kwargs) -> Result<Value, Error> {
    move |args: &[Value], _kwargs: Kwargs| -> Result<Value, Error> {
        if args.len() != 1 {
            return Err(Error::new(
                ErrorKind::InvalidOperation,
                "set_strict requires exactly 1 argument",
            ));
        }

        let value = &args[0];
        match value.try_iter() {
            Ok(iter) => {
                let set: BTreeSet<_> = iter.map(|v| v.to_string()).collect();
                Ok(Value::from_iter(set))
            }
            Err(_) => Err(Error::new(
                ErrorKind::InvalidOperation,
                "set_strict requires an iterable value",
            )),
        }
    }
}

View on GitHub (pinned to 0267ce9170)

Solutions

  1. Pass exactly one iterable: set_strict(my_list)
  2. To combine lists, concatenate first: set_strict(list_a + list_b)
  3. Remove extra positional arguments

Example fix

// before
{% set s = set_strict(list_a, list_b) %}
// after
{% set s = set_strict(list_a + list_b) %}
Defensive patterns

Strategy: validation

Validate before calling

{% if lists is not sequence %}
  {{ exceptions.raise_compiler_error('set_strict() needs one iterable in ' ~ this) }}
{% endif %}
{% set s = set_strict(lists) %}

Type guard

{% macro one_iterable(args) %}{{ return(args | length == 1 and args[0] is sequence) }}{% endmacro %}

Prevention

When it happens

Trigger: Calling set_strict() with zero arguments, or set_strict(a, b) with two or more positional arguments. Calling with kwargs only also triggers it since positional args are counted.

Common situations: Passing multiple lists expecting them to be merged — set_strict takes one iterable only; porting calls from set() where two args were tolerated into set_strict() where they are not.

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/8a25b0ff0053ba04. Report an issue: GitHub.