[v2 Bug] information schema: node_columns.constraints and models.constraints are always NULL and unavailable to checks
Is this a new bug in dbt v2.x compared to the latest version of dbt 1.x?
- I believe this is a new bug in dbt v2.x
- I have searched the existing issues and could not find a duplicate (closest: #16043, #15850, #15845 — none lists
constraints)
Current Behavior
The information schema columns dbt.node_columns.constraints and dbt.models.constraints are always NULL, even for a project that declares column-level and model-level constraints. The same data is present in target/manifest.json, so it is lost between parsing and the information schema, not missing from the project.
The two columns are also not available to checks at all: a check that selects constraints from info_schema('models') or info_schema('node_columns') fails with a binder error, so a check cannot rely on declared constraints.
Expected Behavior
node_columns.constraintsholds the column's declared constraints (for example the JSON array[{"type":"not_null"}, ...]), andmodels.constraintsholds the model-level constraints.- Once populated,
constraintsis also exposed in the views that checks can query, so a check can use it.
Use case: dbt-project-evaluator 1.x treats a not_null column constraint as equivalent to a not_null test in its "missing primary key tests" rule (a unique test plus a not_null constraint is a tested primary key). A native-check port of that rule cannot reproduce this today, so projects that rely on contracts get false positives.
Steps To Reproduce
dbt_project.yml
name: repro_info_schema_constraints
version: '1.0.0'
profile: repro_info_schema_constraints
model-paths: ["models"]
info_schema:
version: 1profiles.yml
repro_info_schema_constraints:
target: dev
outputs:
dev:
type: duckdb
path: dev.duckdb
threads: 1models/orders.sql
select 1 as order_id, 2 as customer_idmodels/orders.yml
models:
- name: orders
config:
contract: {enforced: true}
constraints:
- type: primary_key
columns: [order_id]
columns:
- name: order_id
data_type: int
constraints:
- type: not_null
- type: primary_key
- name: customer_id
data_type: int
constraints:
- type: not_nulldbt parse --generate-info-schema(the result is the same afterdbt compile --generate-info-schemaanddbt build --generate-info-schema)- Count the populated values:Output:
dbt show --inline "select (select count(*) from {{ info_schema('node_columns') }} where constraints is not null) as col_non_null, (select count(*) from {{ info_schema('models') }} where constraints is not null) as model_non_null, (select count(*) from {{ info_schema('node_columns') }}) as n_cols"col_non_null = 0,model_non_null = 0,n_cols = 2. - For comparison,
target/manifest.jsonhasnodes["model.repro_info_schema_constraints.orders"].constraints(the model-levelprimary_key) and.columns.order_id.constraints(not_nullandprimary_key). - Check-time view: add
checks/constraints_probe.sqland runselect m.name, m.constraints, c.constraints from {{ info_schema('models') }} m join {{ info_schema('node_columns') }} c on c.node_unique_id = m.unique_iddbt check constraints_probe.
Relevant log output
[error] [CheckEvaluationFailed (dbt1653)]: check 'constraints_probe' could not be evaluated:
Binder Error: Values list "m" does not have a column named "constraints"What looks like the cause (public source)
Pointers are to dbt-labs/dbt-fusion at 9977b6c (2026-06-04), the most recent public snapshot. I read a newer tree and the logic is the same.
crates/dbt-metadata-parquet/src/parse_columns.rs:ParseColumnRowhasis_primary_key,constraints(full constraints JSON),metaandgranularity, so the parse step does record them.crates/dbt-index-core/src/ingest/metadata_to_parquet.rs,write_parse_columns(~L1627): the row pushed intonode_columnsonly readsunique_id,column_name,declared_type,descriptionandtags;constraints(andmeta,granularity) are dropped.- The two later merges into
node_columns(the catalog and compile column projections,// column_constraintsat ~L2177 and ~L2363) writenull_strforcolumn_constraints, so nothing fills it afterwards. - The model-level reader (
node_constraints, read fromconstraintsin the model attributes) is there, butmodels.constraintsis stillNULLin the repro, so the value is not reaching that point either. - In the newer tree, the parse-time views used by checks leave
constraintsout, with the comment that no writer fills it. So once the writer is fixed, the column also needs adding to those views.
This looks like another entry for the "columns exposed but never filled" list in #16043. node_columns.meta and granularity appear to be dropped by the same function for the same reason, though I only verified constraints.
Environment
- OS: macOS
- CPU: ARM
- dbt distribution and version: dbt 2.0.6
Which database adapter are you using?
duckdb (not adapter-specific)
Source: dbt-labs/dbt-core