{"record":{"id":"f867245fa46356ab","repo":"dbt-labs/dbt-core","slug":"render-constraints-for-create-is-only-available-fo","errorCode":null,"errorMessage":"render_constraints_for_create is only available for Databricks relations","messagePattern":"render_constraints_for_create is only available for Databricks relations","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-adapter/src/relation/relation_object.rs","lineNumber":136,"sourceCode":"                        minijinja::Error::new(\n                            minijinja::ErrorKind::InvalidOperation,\n                            \"enrich constraints must contain TypedConstraint objects\",\n                        )\n                    })\n            })\n            .collect::<Result<Vec<_>, _>>()?;\n        let enriched = dbx.enrich(&constraints);\n        Ok(RelationObject::new(Arc::new(enriched)).into_value())\n    }\n\n    /// Databricks: render constraints DDL for CREATE TABLE\n    fn relation_render_constraints_for_create(self: &Arc<Self>) -> Result<Value, minijinja::Error> {\n        let dbx = self\n            .relation\n            .as_any()\n            .downcast_ref::<Relation>()\n            .ok_or_else(|| {\n                minijinja::Error::new(\n                    minijinja::ErrorKind::InvalidOperation,\n                    \"render_constraints_for_create is only available for Databricks relations\",\n                )\n            })?;\n        Ok(Value::from(dbx.render_constraints_for_create()))\n    }\n}\n\n/// Always returns the unfiltered relation string (via [`BaseRelation::render_self_as_str`]),\n/// reference: https://github.com/dbt-labs/dbt-adapters/blob/616a8d3cb595605872c011070c240e7a2b825d79/dbt-adapters/src/dbt/adapters/base/relation.py#L268-L269\nfn render_without_filter(ro: &Arc<RelationObject>) -> Value {\n    let rendered = ro.render_self_as_str();\n    if rendered.is_empty() {\n        none_value()\n    } else {\n        Value::from(rendered)\n    }\n}","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-adapter/src/relation/relation_object.rs#L118-L154","documentation":"The `render_constraints_for_create` Jinja method on a relation object is only implemented for Databricks relations. The object method attempts a downcast of the wrapped relation to the Databricks `Relation` type and throws this minijinja InvalidOperation error when the relation is any other adapter's relation type. It is a deliberate adapter-capability guard, not a bug.","triggerScenarios":"Calling `relation.render_constraints_for_create()` from a macro or Jinja template while running under a non-Databricks adapter, or when the wrapped value is a generic/base relation rather than the concrete Databricks Relation object.","commonSituations":"Porting a Databricks-specific macro (e.g. model constraints in CREATE TABLE) to another warehouse like Snowflake or BigQuery; a shared macro package that assumes Databricks; calling the method on a relation built from a generic BaseRelation instead of the adapter's relation.","solutions":["Guard the call with the adapter type: only call `render_constraints_for_create()` when `adapter.type() == 'databricks'`.","In cross-adapter macros, branch on `adapter.type()` and fall back to standard constraint rendering for other adapters.","Ensure the relation object was created by the Databricks adapter (e.g. via `api.Relation.create` on the Databricks adapter), not a generic base relation."],"exampleFix":"// before\n{{ relation.render_constraints_for_create() }}\n// after\n{% if adapter.type() == 'databricks' %}\n  {{ relation.render_constraints_for_create() }}\n{% else %}\n  {{ render_standard_constraints(relation) }}\n{% endif %}","handlingStrategy":"validation","validationCode":"{% if adapter.type() == 'databricks' %}\n  {{ relation.render_constraints_for_create() }}\n{% else %}\n  {{ render_standard_constraints(relation) }}\n{% endif %}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Gate Databricks-only relation methods on `adapter.type()` checks.","Keep cross-warehouse macros free of adapter-specific relation methods.","Document adapter-specific Jinja APIs in shared macro packages."],"tags":["jinja","adapter","databricks","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}