{"record":{"id":"a05068c3611192bb","repo":"dbt-labs/dbt-core","slug":"set-requires-1-argument","errorCode":null,"errorMessage":"set() requires 1 argument","messagePattern":"set\\(\\) requires 1 argument","errorType":"validation","errorClass":"InvalidOperation","httpStatus":null,"severity":"error","filePath":"crates/dbt-jinja-utils/src/functions/base.rs","lineNumber":688,"sourceCode":"/// Convert any iterable to a set with unique elements.\n///\n/// Args:\n///     value: An iterable value to convert to a set (required)\n///     default: (optional) Value to return if conversion fails (can be passed\n///              as second positional argument or kwarg: default=\"...\")\n///\n/// Example:\n/// ```jinja\n/// {% set my_list = [1, 2, 2, 3] %}\n/// {% set unique_values = set(my_list) %}\n/// -- Returns set with {1, 2, 3}\n/// {% set empty = set([]) %}\n/// -- Returns empty set\n/// ```\npub fn set_fn() -> impl Fn(&[Value], Kwargs) -> Result<Value, Error> {\n    move |args: &[Value], kwargs: Kwargs| -> Result<Value, Error> {\n        if args.is_empty() || args.len() > 2 {\n            return Err(Error::new(\n                ErrorKind::InvalidOperation,\n                \"set() requires 1 argument\",\n            ));\n        }\n\n        let mut arg_parser = ArgParser::new(args, Some(kwargs));\n        let value = arg_parser.get::<Value>(\"value\")?;\n        let default = arg_parser.get_optional::<Value>(\"default\");\n\n        match value.try_iter() {\n            Ok(iter) => Ok(Value::from_object(iter.collect::<MutableSet>())),\n            Err(_) => match default {\n                Some(def) => Ok(def),\n                None => Ok(Value::from(())),\n            },\n        }\n    }\n}","sourceCodeStart":670,"sourceCodeEnd":706,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-jinja-utils/src/functions/base.rs#L670-L706","documentation":"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.","triggerScenarios":"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'.","commonSituations":"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.","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)"],"exampleFix":"// before\n{% set s = set() %}\n// after\n{% set s = set([]) %}","handlingStrategy":"validation","validationCode":"{% if my_list is not sequence %}\n  {{ exceptions.raise_compiler_error('set() expects a list in ' ~ this) }}\n{% endif %}\n{% set s = set(my_list) %}","typeGuard":"{% macro is_settable(x) %}{{ return(x is defined and x is sequence) }}{% endmacro %}","tryCatchPattern":null,"preventionTips":["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"],"tags":["jinja","dbt","argument-count"],"backgroundTag":"missing-required-argument","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"}