dbt-labs/dbt-core · error · InvalidOperation
set() requires 1 argument
Error message
set() requires 1 argument
What it means
set() converts a list (or other iterable) into a dbt set with unique values. The implementation accepts 1 or 2 positional arguments; zero arguments or more than two triggers this InvalidOperation error. It guards the arity before the ArgParser processes the iterable.
Source
Thrown at crates/dbt-jinja-utils/src/functions/base.rs:688
/// Convert any iterable to a set with unique elements.
///
/// Args:
/// value: An iterable value to convert to a set (required)
/// default: (optional) Value to return if conversion fails (can be passed
/// as second positional argument or kwarg: default="...")
///
/// Example:
/// ```jinja
/// {% set my_list = [1, 2, 2, 3] %}
/// {% set unique_values = set(my_list) %}
/// -- Returns set with {1, 2, 3}
/// {% set empty = set([]) %}
/// -- Returns empty set
/// ```
pub fn set_fn() -> impl Fn(&[Value], Kwargs) -> Result<Value, Error> {
move |args: &[Value], kwargs: Kwargs| -> Result<Value, Error> {
if args.is_empty() || args.len() > 2 {
return Err(Error::new(
ErrorKind::InvalidOperation,
"set() requires 1 argument",
));
}
let mut arg_parser = ArgParser::new(args, Some(kwargs));
let value = arg_parser.get::<Value>("value")?;
let default = arg_parser.get_optional::<Value>("default");
match value.try_iter() {
Ok(iter) => Ok(Value::from_object(iter.collect::<MutableSet>())),
Err(_) => match default {
Some(def) => Ok(def),
None => Ok(Value::from(())),
},
}
}
}View on GitHub (pinned to 0267ce9170)
Solutions
- Pass exactly one list argument: set(my_list)
- For an empty set use set([]) instead of set()
- Remove any extra positional arguments beyond the iterable (kwargs like fillvalue may be fine for zip but check the set API)
Example fix
// before
{% set s = set() %}
// after
{% set s = set([]) %} Defensive patterns
Strategy: validation
Validate before calling
{% if my_list is not sequence %}
{{ exceptions.raise_compiler_error('set() expects a list in ' ~ this) }}
{% endif %}
{% set s = set(my_list) %} Type guard
{% macro is_settable(x) %}{{ return(x is defined and x is sequence) }}{% endmacro %} Prevention
- Never call set() with zero args; use set([]) for an empty set
- Keep positional args to at most two
- Remember Python's set() has no Jinja equivalent
When it happens
Trigger: Calling set() with no arguments, or set(a, b, c) with three or more positional arguments. Note set(a, b) is allowed (two args), only 0 or 3+ are rejected despite the message saying 'requires 1 argument'.
Common situations: Porting Python habits like set() for an empty set into Jinja where that arity is invalid; accidentally leaving a trailing comma or spread that adds extra positional args; converting Python code that used set literals incorrectly.
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
- diff_of_two_dicts requires exactly 2 arguments
- render requires exactly one argument (the string to render)
- set_strict requires exactly 1 argument
- zip requires at least 1 argument
- has_var requires 1 argument
AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07).
Data as JSON: /api/errors/a05068c3611192bb.
Report an issue: GitHub.