{"record":{"id":"041daf6462be4214","repo":"dbt-labs/dbt-core","slug":"parse-constraints-e","errorCode":null,"errorMessage":"parse_constraints: {e}","messagePattern":"parse_constraints: (.+?)","errorType":"exception","errorClass":"minijinja::Error::InvalidOperation","httpStatus":null,"severity":"error","filePath":"crates/dbt-adapter/src/adapter/adapter_impl.rs","lineNumber":4691,"sourceCode":"            })?;\n\n        let model_constraints_vec: Vec<ModelConstraint> =\n            minijinja_value_to_typed_struct(model_constraints.clone()).map_err(|e| {\n                minijinja::Error::new(\n                    minijinja::ErrorKind::SerdeDeserializeError,\n                    format!(\"model_constraints: {e}\"),\n                )\n            })?;\n\n        let column_refs: Vec<DbtColumnRef> = model_columns_map\n            .values()\n            .map(|c| Arc::new(c.clone()))\n            .collect();\n\n        let (not_nulls, typed_constraints) = if contract_enforced {\n            typed_constraint::parse_constraints(&column_refs, &model_constraints_vec).map_err(\n                |e| {\n                    minijinja::Error::new(\n                        minijinja::ErrorKind::InvalidOperation,\n                        format!(\"parse_constraints: {e}\"),\n                    )\n                },\n            )?\n        } else {\n            if model_columns_map\n                .values()\n                .any(|column| !column.constraints.is_empty())\n            {\n                let model_ref = if model_name.is_empty() {\n                    String::new()\n                } else {\n                    format!(\" on '{model_name}'\")\n                };\n                emit_info_log_message(format!(\n                    \"Skipping column-level constraints{model_ref}: set `contract.enforced: true` \\\n                     to apply NOT NULL / primary key / foreign key / check constraints.\"","sourceCodeStart":4673,"sourceCodeEnd":4709,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-adapter/src/adapter/adapter_impl.rs#L4673-L4709","documentation":"This error is raised by `typed_constraint::parse_constraints` when a contract-enforced model's column refs and model constraints cannot be parsed into not-null lists and typed constraints. The library wraps the failure as a minijinja InvalidOperation with the message 'parse_constraints: {e}'. It indicates the constraints declared on a contracted model are invalid for the columns they reference.","triggerScenarios":"Materializing a model with `contract: {enforced: true}` where `parse_constraints(&column_refs, &model_constraints_vec)` fails — e.g. a constraint references a column name not present in column_refs, or a constraint type is incompatible with the declared column data type.","commonSituations":"Developers hit this when adding model contracts: a constraint names a column that was renamed or removed, a `check` constraint lacks an expression, or a foreign_key constraint references a missing column, all while contract enforcement is on.","solutions":["Read the inner error text after 'parse_constraints: ' to find the offending constraint/column","Verify every constraint's column matches a column defined in the model's `columns:` block","Remove or fix constraints whose type is invalid for the column's data_type (contract validation is strict)","Disable contract enforcement (`contract.enforced: false`) if contracts are not actually needed while debugging"],"exampleFix":"// before\ncolumns:\n  - name: user_id\n    constraints:\n      - type: foreign_key\n// after\ncolumns:\n  - name: user_id\n    constraints:\n      - type: foreign_key\n        expression: other_table (id)","handlingStrategy":"validation","validationCode":"// before materializing a contracted model\nlet constraint_columns: HashSet<&str> = model_constraints.iter().filter_map(|c| c.columns.as_ref()).flatten().map(|s| s.as_str()).collect();\nlet defined: HashSet<&str> = column_refs.iter().map(|c| c.name.as_str()).collect();\nlet dangling: Vec<_> = constraint_columns.difference(&defined).collect();\nif !dangling.is_empty() { return Err(format!(\"constraints reference unknown columns: {dangling:?}\")); }","typeGuard":"fn constraint_columns_exist(constraints: &[ModelConstraint], cols: &[DbtColumnRef]) -> bool {\n    let names: HashSet<&str> = cols.iter().map(|c| c.name()).collect();\n    constraints.iter().all(|c| c.referenced_columns().iter().all(|col| names.contains(col.as_str())))\n}","tryCatchPattern":"match typed_constraint::parse_constraints(&column_refs, &model_constraints_vec) {\n    Ok(r) => r,\n    Err(e) => return Err(minijinja::Error::new(minijinja::ErrorKind::InvalidOperation,\n        format!(\"parse_constraints: {e}; check constraint column references and contract config\"))),\n}","preventionTips":["Run dbt compile with contract enforced locally to catch constraint errors early","Ensure every constraint column exists in the model's columns block","Rename-dependent constraints should be updated whenever columns are renamed"],"tags":["contracts","constraints","validation","snowflake"],"backgroundTag":"schema-validation-failed","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"}