Skip to content

Commit

Permalink
allow on_schema_change: fail for incremental models with contracts (#…
Browse files Browse the repository at this point in the history
…8006)

(cherry picked from commit 7ea51df)
  • Loading branch information
MichelleArk authored and github-actions[bot] committed Jul 5, 2023
1 parent 3e5e693 commit c0b8519
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230629-221615.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Allow on_schema_change = fail for contracted incremental models
time: 2023-06-29T22:16:15.34895-04:00
custom:
Author: michelleark
Issue: "7975"
4 changes: 2 additions & 2 deletions core/dbt/contracts/graph/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,12 @@ def __post_init__(self):
if (
self.contract.enforced
and self.materialized == "incremental"
and self.on_schema_change != "append_new_columns"
and self.on_schema_change not in ("append_new_columns", "fail")
):
raise ValidationError(
f"Invalid value for on_schema_change: {self.on_schema_change}. Models "
"materialized as incremental with contracts enabled must set "
"on_schema_change to 'append_new_columns'"
"on_schema_change to 'append_new_columns' or 'fail'"
)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/configs/test_contract_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def test__config_errors(self, project):
run_dbt(["run"], expect_pass=False)

exc_str = " ".join(str(err_info.value).split())
expected_materialization_error = "Invalid value for on_schema_change: ignore. Models materialized as incremental with contracts enabled must set on_schema_change to 'append_new_columns'"
expected_materialization_error = "Invalid value for on_schema_change: ignore. Models materialized as incremental with contracts enabled must set on_schema_change to 'append_new_columns' or 'fail'"
assert expected_materialization_error in str(exc_str)


Expand Down

0 comments on commit c0b8519

Please sign in to comment.