{"record":{"id":"913dc381d8befdd7","repo":"dbt-labs/dbt-core","slug":"get-csv-data-failed-to-format-csv-e","errorCode":null,"errorMessage":"get_csv_data: failed to format CSV: {e}","messagePattern":"get_csv_data: failed to format CSV: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-adapter/src/adapter/mod.rs","lineNumber":4414,"sourceCode":"        let iter = ArgsIter::new(\"get_credentials\", &[\"connection_overrides\"], args);\n        let overrides = iter.next_arg::<Option<&Value>>()?;\n        iter.finish()?;\n        match &self.inner {\n            Typed { adapter, .. } => {\n                Ok(adapter.get_credentials(overrides.unwrap_or(&Value::UNDEFINED)))\n            }\n            Parse(_) => Ok(empty_map_value()),\n        }\n    }\n\n    pub fn get_csv_data(&self, table: Arc<AgateTable>) -> Result<Value, minijinja::Error> {\n        let batch = table.original_record_batch();\n        let mut buf: Vec<u8> = Vec::new();\n        let mut writer = arrow::csv::WriterBuilder::new()\n            .with_header(false)\n            .build(&mut buf);\n        writer.write(&batch).map_err(|e| {\n            minijinja::Error::new(\n                minijinja::ErrorKind::InvalidOperation,\n                format!(\"get_csv_data: failed to format CSV: {e}\"),\n            )\n        })?;\n        drop(writer);\n        Ok(Value::from(String::from_utf8_lossy(&buf).into_owned()))\n    }\n}\n\n/// Adapter methods whose `Parse`-mode implementation independently\n/// fabricates relation/table/column/schema-shaped data (rather than\n/// returning a trivial `bool`/`none` placeholder) instead of ever calling\n/// `execute`. Each of these needs to be tainted individually at the\n/// dispatch point below -- there is no single shared call they all funnel\n/// through to taint once. This is the canonical list; minijinja's\n/// `INTROSPECTIVE_METHOD_NAMES` (used for the static \"does this macro reach\n/// an introspective call\" analysis) must be kept in sync with it, since\n/// minijinja cannot depend on this crate to reuse it directly.","sourceCodeStart":4396,"sourceCodeEnd":4432,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-adapter/src/adapter/mod.rs#L4396-L4432","documentation":"`get_csv_data` converts the table's underlying Arrow record batch to CSV bytes using `arrow::csv::Writer`. If the Arrow CSV writer fails to serialize the batch (unsupported column type, Arrow writer error, invalid batch state), the error is wrapped as this `InvalidOperation` minijinja error and surfaced to the macro caller.","triggerScenarios":"Calling `adapter.get_csv_data(agate_table)` where the table's original record batch contains data the Arrow CSV writer cannot serialize — e.g. unusual/nested column types (lists, structs) that the writer rejects, or a corrupt/invalid record batch.","commonSituations":"Seed files with nested or exotic column types parsed into complex Arrow types; tables whose schema was transformed by custom macros into unsupported types; very wide seeds hitting writer constraints; engine-internal Arrow errors while writing.","solutions":["Inspect the inner `{e}` message to identify which column/type the Arrow writer rejected.","Flatten or cast unsupported columns (nested lists/structs) to primitive types before calling get_csv_data.","Check the seed CSV source for malformed rows that produced an invalid record batch.","If the type is legitimately unsupported, fall back to a macro-level CSV rendering of the table's rows/columns."],"exampleFix":"// before (Jinja): table has a nested struct column the Arrow CSV writer cannot serialize\n{% set csv = adapter.get_csv_data(agate_table) %}\n// after: cast/select only primitive columns first\n{% set simple = agate_table.select_columns(['id','name','value']) %}\n{% set csv = adapter.get_csv_data(simple) %}","handlingStrategy":"try-catch","validationCode":"{# Jinja: pre-check column types if the table exposes its schema #}\n{% for col in agate_table.column_names %}\n  {# cast or drop non-primitive columns before serialization #}\n{% endfor %}","typeGuard":null,"tryCatchPattern":"{# Jinja: fallback rendering if Arrow CSV serialization fails #}\n{% set csv = adapter.get_csv_data(agate_table) %}\n{% if csv is undefined %}\n  {# build CSV manually from rows as fallback #}\n{% endif %}","preventionTips":["Keep seed columns to primitive types (string, int, float, bool, date) for CSV serialization.","Flatten nested/struct columns before calling get_csv_data.","Validate source CSVs for malformed rows before they become record batches.","Check the inner Arrow error message to identify the offending column type."],"tags":["csv","arrow","serialization","jinja"],"backgroundTag":"json-serialization-failed","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"}