{"record":{"id":"1826f7ede433ef75","repo":"dbt-labs/dbt-core","slug":"set-strict-requires-an-iterable-value","errorCode":null,"errorMessage":"set_strict requires an iterable value","messagePattern":"set_strict requires an iterable value","errorType":"validation","errorClass":"InvalidOperation","httpStatus":null,"severity":"error","filePath":"crates/dbt-jinja-utils/src/functions/base.rs","lineNumber":779,"sourceCode":"/// {% set unique_values = set_strict(my_list) %}\n/// -- Returns [1, 2, 3] or fails if my_list is not iterable\n/// ```\npub fn set_strict_fn() -> impl Fn(&[Value], Kwargs) -> Result<Value, Error> {\n    move |args: &[Value], _kwargs: Kwargs| -> Result<Value, Error> {\n        if args.len() != 1 {\n            return Err(Error::new(\n                ErrorKind::InvalidOperation,\n                \"set_strict requires exactly 1 argument\",\n            ));\n        }\n\n        let value = &args[0];\n        match value.try_iter() {\n            Ok(iter) => {\n                let set: BTreeSet<_> = iter.map(|v| v.to_string()).collect();\n                Ok(Value::from_iter(set))\n            }\n            Err(_) => Err(Error::new(\n                ErrorKind::InvalidOperation,\n                \"set_strict requires an iterable value\",\n            )),\n        }\n    }\n}\n\n/// Try to call a function and raise a CompilationError if it raises an exception.\n///\n/// Args:\n///     message_if_exception: The message to raise if the function raises an exception\n///     func: The function to call\n///     *args: The arguments to pass to the function\n///     **kwargs: The keyword arguments to pass to the function\n///\n/// Example:\n/// ```jinja\n/// {% set result = try_or_compiler_error(\"Error\", my_function, arg1, arg2, kwarg1=\"value1\", kwarg2=\"value2\") %}","sourceCodeStart":761,"sourceCodeEnd":797,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-jinja-utils/src/functions/base.rs#L761-L797","documentation":"set_strict() calls try_iter() on its single argument and throws this InvalidOperation error when the value is not iterable (e.g. a string is technically iterable in some engines, but numbers, booleans, dicts-as-scalars, or none are not usable here). The 'strict' contract is to fail rather than silently coerce.","triggerScenarios":"Calling set_strict(5), set_strict(none), set_strict(my_dict) where my_dict iteration is not supported, or set_strict(undefined_var) where the variable never got assigned a list.","commonSituations":"A config or var expected to be a list but supplied as a scalar (var('x') default being a string/number); a Jinja expression returning none due to a failed lookup upstream; refactors changing a variable from list to scalar.","solutions":["Ensure the argument is a list/sequence: set_strict([1,2,3])","Coerce scalars into a one-element list: set_strict([value])","Use var('x', []) with a list default, or validate with `x is iterable` / sequence test before calling"],"exampleFix":"// before\n{% set s = set_strict(var('ids')) %}\n// after\n{% set ids = var('ids', []) %}\n{% set s = set_strict(ids if ids is sequence else [ids]) %}","handlingStrategy":"validation","validationCode":"{% if ids is not sequence %}\n  {% set ids = [ids] %}\n{% endif %}\n{% set s = set_strict(ids) %}","typeGuard":"{% macro as_list(x) %}{{ return(x if x is sequence else [x]) }}{% endmacro %}","tryCatchPattern":null,"preventionTips":["Give var() calls list defaults: var('ids', [])","Normalize scalars to single-element lists before set_strict","Check upstream lookups for none results before passing them in"],"tags":["jinja","dbt","not-iterable"],"backgroundTag":"type-mismatch","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}