dbt-labs/dbt-core · error · minijinja::Error::SerdeDeserializeError

{e}

Error message

{e}

What it means

`render_raw_model_constraints` deserializes its `raw_constraints` argument into `Vec<ModelConstraint>` using `minijinja_value_to_typed_struct`; any serde failure is re-raised as a SerdeDeserializeError whose message is the serde error text. The library throws it because rendered constraint SQL requires well-typed ModelConstraint inputs.

Source

Thrown at crates/dbt-adapter/src/adapter/mod.rs:782

    /// ) -> List[str]
    ///
    /// ```
    #[tracing::instrument(skip_all, level = "trace")]
    pub fn render_raw_model_constraints(
        &self,
        state: &State,
        args: &[Value],
    ) -> Result<Value, minijinja::Error> {
        match &self.inner {
            Typed { adapter, .. } => {
                let iter =
                    ArgsIter::new("render_raw_model_constraints", &["raw_constraints"], args);
                let raw_constraints_val = iter.next_arg::<&Value>()?;
                let raw_constraints = minijinja_value_to_typed_struct::<Vec<ModelConstraint>>(
                    raw_constraints_val.clone(),
                )
                .map_err(|e| {
                    minijinja::Error::new(
                        minijinja::ErrorKind::SerdeDeserializeError,
                        e.to_string(),
                    )
                })?;
                iter.finish()?;

                if let Some(replay_adapter) = adapter.as_replay() {
                    return replay_adapter
                        .replay_render_raw_model_constraints(state, &raw_constraints);
                }
                let mut result = vec![];
                for constraint in &raw_constraints {
                    warn_constraint_support(
                        adapter.adapter_type(),
                        constraint.type_,
                        adapter.get_constraint_support(constraint.type_),
                        constraint.warn_unsupported,
                        constraint.warn_unenforced,

View on GitHub (pinned to 0267ce9170)

Solutions

  1. Read the appended serde message to identify which constraint field failed (e.g. missing 'type', invalid enum variant)
  2. Normalize each constraint to a mapping with a valid `type` and optional `name`, `expression`, `columns` fields before calling
  3. Check for version skew between dbt-core (which serializes constraints) and this adapter crate
  4. Guard the call site with a check that raw_constraints is a list before invoking

Example fix

// before
render_raw_model_constraints(constraints)  # constraints = ["not_null"]
// after
render_raw_model_constraints([{'type': 'not_null'}])
Defensive patterns

Strategy: validation

Validate before calling

// guard before calling
if !raw_constraints.is_array() || raw_constraints.iter().any(|c| !c.is_object() || c.get("type").is_none()) {
    return Err("raw_constraints must be a list of objects each with a 'type' field".into());
}

Type guard

fn is_constraint_list(v: &Value) -> bool {
    v.try_iter().map(|it| it.all(|c| c.get_attr("type").is_ok())).unwrap_or(false)
}

Try / catch

let raw_constraints = minijinja_value_to_typed_struct::<Vec<ModelConstraint>>(raw_constraints_val.clone())
    .map_err(|e| minijinja::Error::new(minijinja::ErrorKind::SerdeDeserializeError,
        format!("raw_constraints: {e}; each constraint needs a valid 'type'")))?;

Prevention

When it happens

Trigger: Calling render_raw_model_constraints with raw_constraints that do not deserialize as a list of ModelConstraint — e.g. raw constraint dicts from the manifest lacking required fields, or constraints passed as plain strings.

Common situations: Models whose YAML constraints use an unexpected structure, custom materializations forwarding manifest values verbatim, or schema drift between dbt-core constraint serialization and the adapter's ModelConstraint struct.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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