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

allow on_schema_change: fail for incremental models with contracts #8006

Merged
merged 3 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -495,12 +495,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