{"record":{"id":"2917c695ce9996a8","repo":"dbt-labs/dbt-core","slug":"agate-table-must-be-an-agatetable","errorCode":null,"errorMessage":"agate_table must be an AgateTable","messagePattern":"agate_table must be an AgateTable","errorType":"exception","errorClass":"minijinja::Error::InvalidOperation","httpStatus":null,"severity":"error","filePath":"crates/dbt-adapter/src/adapter/mod.rs","lineNumber":741,"sourceCode":"    /// https://github.com/dbt-labs/dbt-adapters/blob/main/dbt-adapters/src/dbt/adapters/base/impl.py#L1221\n    ///\n    /// ```python\n    /// def convert_type(\n    ///     cls,\n    ///     agate_table: \"agate.Table\",\n    ///     col_idx: int\n    /// ) -> Optional[str]\n    /// ```\n    #[tracing::instrument(skip_all, level = \"trace\")]\n    pub fn convert_type(&self, state: &State, args: &[Value]) -> Result<Value, minijinja::Error> {\n        match &self.inner {\n            Typed { adapter, .. } => {\n                let iter = ArgsIter::new(\"convert_type\", &[\"agate_table\", \"col_idx\"], args);\n                let table = iter\n                    .next_arg::<&Value>()?\n                    .downcast_object::<AgateTable>()\n                    .ok_or_else(|| {\n                        minijinja::Error::new(\n                            minijinja::ErrorKind::InvalidOperation,\n                            \"agate_table must be an AgateTable\",\n                        )\n                    })?;\n                let col_idx = iter.next_arg::<i64>()?;\n                iter.finish()?;\n\n                let result = adapter.convert_type(state, table, col_idx)?;\n                Ok(Value::from(result))\n            }\n            Parse(_) => Ok(empty_string_value()),\n        }\n    }\n\n    /// Render raw model constraints.\n    ///\n    /// https://github.com/dbt-labs/dbt-adapters/blob/main/dbt-adapters/src/dbt/adapters/base/impl.py#L1891\n    ///","sourceCodeStart":723,"sourceCodeEnd":759,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-adapter/src/adapter/mod.rs#L723-L759","documentation":"`convert_type` converts an AgateTable column's agate type to the adapter's SQL data type. It requires the first argument (`agate_table`) to downcast to an AgateTable; this error is thrown when it cannot. The library enforces the type so it can index into the table's column type list with `col_idx`.","triggerScenarios":"Calling convert_type(agate_table, col_idx) with a value that is not an AgateTable — e.g. passing the table as a serialized dict, a list of columns, or forgetting that the macro wrapper should pass the loaded agate table.","commonSituations":"Custom type-conversion macros (type_code / convert_type hooks) receive raw query results from an overridden load_dataframe or a custom materialization passes the wrong variable.","solutions":["Ensure the caller wraps results in an AgateTable via load_agate_table() before invoking convert_type","Check that the table object, not a column or a row, is being passed as the first argument","If calling from Rust, pass Value::from_object(AgateTable) rather than Value::from_serialize"],"exampleFix":"// before\nadapter.convert_type(raw_result, 0)\n// after\nadapter.convert_type(load_agate_table(raw_result), 0)","handlingStrategy":"type-guard","validationCode":"# python guard\nif not isinstance(agate_table, agate.Table):\n    raise TypeError('convert_type requires an agate.Table, got ' + type(agate_table).__name__)","typeGuard":"fn is_agate_table(v: &Value) -> bool {\n    v.downcast_object::<AgateTable>().is_some()\n}","tryCatchPattern":"match value.downcast_object::<AgateTable>() {\n    Some(table) => convert(table, col_idx),\n    None => Err(minijinja::Error::new(minijinja::ErrorKind::InvalidOperation, \"agate_table must be an AgateTable\")),\n}","preventionTips":["Always pass the loaded agate table (load_agate_table result), not raw results","Verify the first argument is the table object, not a column or row","Write a smoke test for custom type-conversion macros"],"tags":["type-conversion","agate","downcast"],"backgroundTag":"invalid-argument-value","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"}