diff --git a/.changes/unreleased/Fixes-20230629-221615.yaml b/.changes/unreleased/Fixes-20230629-221615.yaml new file mode 100644 index 00000000000..43a32ee5e95 --- /dev/null +++ b/.changes/unreleased/Fixes-20230629-221615.yaml @@ -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" diff --git a/core/dbt/contracts/graph/model_config.py b/core/dbt/contracts/graph/model_config.py index 89471df8d5b..fbcfb6d3c56 100644 --- a/core/dbt/contracts/graph/model_config.py +++ b/core/dbt/contracts/graph/model_config.py @@ -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 diff --git a/tests/functional/configs/test_contract_configs.py b/tests/functional/configs/test_contract_configs.py index ae909e6e4bb..a2a2ba8016b 100644 --- a/tests/functional/configs/test_contract_configs.py +++ b/tests/functional/configs/test_contract_configs.py @@ -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)