Skip to content

[CT-2378] [Bug] state:modified not catching breaking changes if model body also changes #7282

@jtcohen6

Description

@jtcohen6

If I change both the contract and the body of a model with an enforced contract, state:modified selects the model without raising the exception added in #6869 / #7216.

Repro case

models:
  - name: my_model
    config:
      contract:
        enforced: true
    columns:
      - name: id
        data_type: int
select 1 as id
$ mkdir state
$ dbt parse
$ mv target/manifest.json state/

If I change just the yaml to data_type: string:

$ dbt ls -s state:modified --state state/
19:17:06  Found 1 model, 0 tests, 0 snapshots, 1 analysis, 522 macros, 0 operations, 1 seed file, 0 sources, 0 exposures, 0 metrics, 0 groups
19:17:06  Running with dbt=1.5.0-b5
...
dbt.exceptions.ModelContractError: Contract Error in model my_model (models/my_model.sql)
  There is a breaking change in the model contract because column definitions have changed; you may need to create a new version. See: https://docs.getdbt.com/docs/collaborate/publish/model-versions

But if I also change the model's SQL to select 1::text as id, such that the contract works again — but has still undergone a breaking change! — it's no longer being caught during the state:modified comparison:

$ dbt ls -s state:modified --state state/
19:17:26  Running with dbt=1.5.0-b5
19:17:26  Found 1 model, 0 tests, 0 snapshots, 1 analysis, 522 macros, 0 operations, 1 seed file, 0 sources, 0 exposures, 0 metrics, 0 groups
test.my_model

If I had to take a wild guess, this is because the model is first selected on the basis of the change to its body, before we get to the same_contract comparison?


If I had my druthers / as a UX improvement, the ModelContractError message would also make clear what in the contract changed (similar to #7209). In practice, the change would also be reflected in the git diff, which someone could inspect in order to understand the cause for the failing CI check.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions