{"record":{"id":"6c122ef55635d577","repo":"dbt-labs/dbt-core","slug":"render-requires-exactly-one-argument-the-string-t","errorCode":null,"errorMessage":"render requires exactly one argument (the string to render)","messagePattern":"render requires exactly one argument \\(the string to render\\)","errorType":"validation","errorClass":"InvalidOperation","httpStatus":null,"severity":"error","filePath":"crates/dbt-jinja-utils/src/functions/base.rs","lineNumber":725,"sourceCode":"/// Renders a string as a Jinja template using the current context.\n///\n/// Args:\n///     sql: The string to render as a template.\n///\n/// Example:\n/// ```jinja\n/// {% set rendered = render(\"Hello {{ this.name }}\") %}\n/// ```\n///\n/// Returns:\n///     The rendered string with all template expressions evaluated in the current context.\n///\n/// Errors:\n///     Raises an error if the argument is not a string or if rendering fails.\npub fn render_fn() -> impl Fn(&State, &[Value], Kwargs) -> Result<Value, Error> {\n    move |state: &State, args: &[Value], _kwargs: Kwargs| -> Result<Value, Error> {\n        if args.len() != 1 {\n            return Err(Error::new(\n                ErrorKind::InvalidOperation,\n                \"render requires exactly one argument (the string to render)\",\n            ));\n        }\n        // dbt-core (Jinja2/Python) effectively accepts any value here and stringifies it.\n        // In practice, many dbt projects call `render(...)` on values that can legitimately be\n        // `none` (e.g. optional metadata-driven SQL snippets from `run_query`), expecting\n        // `\"None\"` and handling that downstream.\n        //\n        // Fusion uses minijinja which is stricter by default; align behavior by accepting\n        // `none` and treating it like Python's `str(None)` => `\"None\"`.\n        let sql = if args[0].is_none() {\n            \"None\"\n        } else {\n            args[0].as_str().ok_or_else(|| {\n                Error::new(ErrorKind::InvalidOperation, \"Argument must be a string\")\n            })?\n        };","sourceCodeStart":707,"sourceCodeEnd":743,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-jinja-utils/src/functions/base.rs#L707-L743","documentation":"render() takes a string, renders it as a Jinja template against the current state, and returns the result. The function requires exactly one positional argument; any other count (zero, or two or more) throws this InvalidOperation error before any rendering happens.","triggerScenarios":"Calling render() with no argument, or render(a, b) with multiple arguments, from a model or macro template. The count check happens before the value is even inspected.","commonSituations":"Attempting to render multiple strings in one call instead of calling render once per string; refactors that dropped the argument; passing kwargs expecting them to count as arguments (they don't).","solutions":["Pass exactly one string argument: render(some_string)","Call render once per string if you have several to render","If the value may be undefined, coalesce first: render(var if var is defined else '')"],"exampleFix":"// before\n{% set out = render(sql_a, sql_b) %}\n// after\n{% set out = render(sql_a ~ sql_b) %}","handlingStrategy":"validation","validationCode":"{% if template_str is not string %}\n  {{ exceptions.raise_compiler_error('render() needs a string in ' ~ this) }}\n{% endif %}\n{% set out = render(template_str) %}","typeGuard":"{% macro is_renderable(x) %}{{ return(x is string or x is none) }}{% endmacro %}","tryCatchPattern":null,"preventionTips":["Call render once per string, never with multiple args","Concatenate strings (~) before rendering rather than passing several","Remember kwargs are not counted as arguments"],"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"}