dbt-labs/dbt-core · error
relation must be an object
Error message
relation must be an object
What it means
downcast_value_to_dyn_base_relation received a minijinja Value that is not an object at all (as_object() returned None) — the argument passed from Jinja to relation-taking adapter methods (drop_relation, truncate_relation, rename_relation, expand_target_column_types, cache handling) is a scalar/string/undefined rather than a relation wrapper.
Solutions
- Pass an actual relation object (api.Relation.create(...) / this) from the Jinja call site
- Guard with is_defined/as_object checks in the macro before calling adapter methods
- Include the received value's type in the error to speed up template debugging
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at crates/dbt-adapter/src/cast_util.rs:19 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/0675ab72ba406d6b.
Report an issue: GitHub.
Appendix: source
Thrown at crates/dbt-adapter/src/cast_util.rs:19
//! A set of util functions for casting from/to Value
use crate::relation::RelationObject;
use dbt_schemas::schemas::relations::base::BaseRelation;
use std::file;
use std::sync::Arc;
pub const THIS_RELATION_KEY: &str = "__this__";
pub fn downcast_value_to_dyn_base_relation(
value: &minijinja::Value,
) -> Result<Arc<dyn BaseRelation>, minijinja::Error> {
if let Some(relation_object) = value.downcast_object::<RelationObject>() {
Ok(relation_object.inner())
} else if let Some(relation_object) = value
.as_object()
.ok_or_else(|| {
minijinja::Error::new(
minijinja::ErrorKind::InvalidOperation,
"relation must be an object",
)
})?
.get_value(&minijinja::Value::from(THIS_RELATION_KEY))
{
Ok(relation_object
.downcast_object::<RelationObject>()
.ok_or_else(|| {
minijinja::Error::new(
minijinja::ErrorKind::InvalidOperation,
"this must be a BaseRelation object",
)
})?
.inner())
} else {
Err(minijinja::Error::new(
minijinja::ErrorKind::InvalidOperation,View on GitHub (pinned to 0267ce9170)