{"record":{"id":"3a00b827f934d43b","repo":"dbt-labs/dbt-core","slug":"write-function-requires-payload-argument","errorCode":null,"errorMessage":"write function requires payload argument","messagePattern":"write function requires payload argument","errorType":"exception","errorClass":"minijinja::Error (InvalidOperation)","httpStatus":null,"severity":"error","filePath":"crates/dbt-jinja-utils/src/phases/run/run_node_context.rs","lineNumber":690,"sourceCode":"\n/// Context function that writes a payload to file\n#[derive(Debug)]\npub struct WriteConfig {\n    /// The resource type string (see `fusion::node::NodeType`)\n    pub resource_type: String,\n    /// Absolute target/run path for this node.\n    pub run_file_path: PathBuf,\n}\n\nimpl Object for WriteConfig {\n    fn call(\n        self: &Arc<Self>,\n        _state: &State<'_, '_>,\n        args: &[MinijinjaValue],\n        _listeners: &[Rc<dyn RenderingEventListener>],\n    ) -> Result<MinijinjaValue, Error> {\n        if args.is_empty() {\n            return Err(Error::new(\n                ErrorKind::InvalidOperation,\n                \"write function requires payload argument\".to_string(),\n            ));\n        }\n\n        // Extract payload from args\n        let payload = match args[0].as_str() {\n            Some(s) => s,\n            None => {\n                return Err(Error::new(\n                    ErrorKind::InvalidOperation,\n                    \"Failed to convert payload to string\".to_string(),\n                ));\n            }\n        };\n\n        // Write the file\n        match write_file(&self.run_file_path, &self.resource_type, payload) {","sourceCodeStart":672,"sourceCodeEnd":708,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-jinja-utils/src/phases/run/run_node_context.rs#L672-L708","documentation":"The write() function exposed on the run-node context requires at least one argument: the payload to write. Called with no arguments, it raises immediately because there is nothing to serialize to the artifact file.","triggerScenarios":"Invoking the write callable from Jinja with zero arguments, e.g. {{ write() }} or assigning write to a variable and calling it without args.","commonSituations":"Typo where an argument is computed conditionally and the call still happens; macro refactors that drop the payload argument; dynamic dispatch where args list is built programmatically and ends up empty.","solutions":["Pass the payload string as the first argument: {{ write(my_payload) }}.","Check that the variable holding the payload is not accidentally omitted during a refactor.","Guard the call site: only call write when content is available."],"exampleFix":"-- before\n{{ write() }}\n-- after\n{{ write(log_message | string) }}","handlingStrategy":"validation","validationCode":"-- Jinja\n{% if payload is defined and payload is not none %}\n  {{ write(payload | string) }}\n{% endif %}","typeGuard":null,"tryCatchPattern":"// Rust-side programmatic invocation\nif args.is_empty() {\n    return Err(Error::new(ErrorKind::InvalidOperation, \"write requires a payload argument\"));\n}","preventionTips":["Always pass payload explicitly to write(); never dispatch it dynamically with a possibly-empty arg list.","Keep write() call sites in one macro so arity mistakes surface in one place.","Add a smoke test invoking write with a trivial payload."],"tags":["jinja","missing-argument","file-write","dbt"],"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"}