dbt-labs/dbt-core · error

argument to () has incompatible type ; expected DataType

Error message

argument {} to {}() has incompatible type {}; expected DataType

What it means

A DataType Jinja method (cast/test/csvify/jsonify) received a 'd' argument that is not a DataType object — downcast_object_ref failed. The helper formats the argument position, method name, and the received type name so the bad call site can be identified.

Solutions

  1. Pass a DataType instance (e.g. from another column's type or a type-tester), not a string or number
  2. Construct the target type via its DataType object in the template
  3. Accept type-name strings by adding a from-string coercion if templates need it
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/dbt-agate/src/data_type.rs:159 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07). Data as JSON: /api/errors/bc052181f4656109. Report an issue: GitHub.

Appendix: source

Thrown at crates/dbt-agate/src/data_type.rs:159

    fn eq(&self, other: &Self) -> bool {
        self.0.eq_repr(&*other.0)
    }
}

impl Object for DataType {
    fn call_method(
        self: &Arc<Self>,
        _state: &State,
        name: &str,
        args: &[Value],
        _listeners: &[Rc<dyn RenderingEventListener>],
    ) -> Result<Value, Error> {
        let as_data_type = |x: &str, fname: &str, value: &Value| {
            value
                .downcast_object_ref::<&dyn DataTypeRepr>()
                .ok_or_else(|| {
                    let got = ArgsIter::type_name_of_value(Some(value));
                    Error::new(
                        ErrorKind::InvalidArgument,
                        format!(
                            "argument {} to {}() has incompatible type {}; expected DataType",
                            x,
                            fname,
                            got.as_ref(),
                        ),
                    )
                })
                .copied()
        };
        match name {
            // DataType methods
            "test" => {
                let args_iter = ArgsIter::new(name, &["d"], args);
                let d = args_iter.next_arg::<&Value>()?;
                args_iter.finish()?;

View on GitHub (pinned to 0267ce9170)