From 7ea51df6aee84be6ed07586fb44d3289ab629b93 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Fri, 30 Jun 2023 10:27:48 -0700 Subject: [PATCH] allow on_schema_change: fail for incremental models with contracts (#8006) --- .changes/unreleased/Fixes-20230629-221615.yaml | 6 ++++++ core/dbt/contracts/graph/model_config.py | 4 ++-- tests/functional/configs/test_contract_configs.py | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 .changes/unreleased/Fixes-20230629-221615.yaml 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)