Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CT-2789] [Bug] Contract checksum not appropriately built for versioned models #8030

Closed
Tracked by #7372
jtcohen6 opened this issue Jul 5, 2023 · 0 comments · Fixed by #8072
Closed
Tracked by #7372

[CT-2789] [Bug] Contract checksum not appropriately built for versioned models #8030

jtcohen6 opened this issue Jul 5, 2023 · 0 comments · Fixed by #8072
Assignees
Labels
Milestone

Comments

@jtcohen6
Copy link
Contributor

jtcohen6 commented Jul 5, 2023

Versioned models do not appropriately generate their contract checksums during parsing, if the contract enforcement config is defined in yaml (as opposed to in-file {{ config }}). Meaning that same_contract checks always return True for this type of versioned model.

Repro case

Start with:

-- models/my_model.sql
select 1 as id
models:
  - name: my_model
    config:
      contract: {enforced: true}
    columns:
      - name: id
        data_type: integer

    versions:
      - v: 1

Generate a manifest and move it to a local folder:

$ mkdir state/
$ dbt parse
$ mv target/manifest.json state/

Change to:

-- models/my_model.sql
select 1 as id
models:
  - name: my_model
    config:
      contract: {enforced: true}
    columns:
      - name: id
        data_type: text

    versions:
      - v: 1

Then select modified models. I expected to see a Breaking Change to Contract Error:

$ dbt -q ls -s state:modified --state state/
09:37:41  Encountered an error:
Breaking Change to Contract Error in model my_model (models/my_model.sql)
  While comparing to previous project state, dbt detected a breaking change to an enforced contract.

  Columns with data_type changes:
   - id (integer -> text)

  Consider making an additive (non-breaking) change instead, if possible.
  Otherwise, create a new model version: https://docs.getdbt.com/docs/collaborate/govern/model-versions

Instead, it succeeds:

$ dbt -q ls -s state:modified --state state/
my_dbt_project.my_model.v1

This should raise a "Breaking Change" error that can be resolved by bumping the model version.

Potential resolutions

The problem is that a versioned model doesn't have its contract checksum appropriately generated, so this check succeeds (both are None):

# Otherwise: The contract was previously enforced, and we need to check for changes.
# Happy path: The contract is still being enforced, and the checksums are identical.
if self.contract.enforced is True and self.contract.checksum == old.contract.checksum:
# No change -- same_contract: True
return True

Two potential fixes:

  1. Within same_contract, if not contract.checksum, generate it: 879957a
  2. During parsing, call build_contract_checksum() for versioned models specifically, after configs are resolved: 434d491
@github-actions github-actions bot changed the title [Bug] Contract checksum not appropriately built for versioned models [CT-2789] [Bug] Contract checksum not appropriately built for versioned models Jul 5, 2023
@jtcohen6 jtcohen6 added this to the v1.5.x milestone Jul 5, 2023
@MichelleArk MichelleArk self-assigned this Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants