#16553·dbt-core

[v2 问题] 信息模式: node_columns.constraints 和 models.constraints 总是为 NULL,无法用于检查

作者: b-per创建于 2026年10月1日更新于 2026年10月1日
标签type:bugengine:v2v2info schema

dbt_project.yml

yaml
name: repro_info_schema_constraints
version: '1.0.0'
profile: repro_info_schema_constraints
model-paths: ["models"]
info_schema:
  version: 1

profiles.yml

yaml
repro_info_schema_constraints:
  target: dev
  outputs:
    dev:
      type: duckdb
      path: dev.duckdb
      threads: 1

models/orders.sql

sql
select 1 as order_id, 2 as customer_id

models/orders.yml

yaml
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_null
  1. dbt parse --generate-info-schema (the result is the same after dbt compile --generate-info-schema and dbt build --generate-info-schema)
  2. Count the populated values:
bash
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"

Output: col_non_null = 0, model_non_null = 0, n_cols = 2. 3. For comparison, target/manifest.json has nodes["model.repro_info_schema_constraints.orders"].constraints (the

内容来源: dbt-labs/dbt-core