diff --git a/.changes/unreleased/Fixes-20230718-125518.yaml b/.changes/unreleased/Fixes-20230718-125518.yaml new file mode 100644 index 00000000000..be3c7e9d8ed --- /dev/null +++ b/.changes/unreleased/Fixes-20230718-125518.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Enable converting deprecation warnings to errors +time: 2023-07-18T12:55:18.03914-04:00 +custom: + Author: michelleark + Issue: "8130" diff --git a/core/dbt/events/types.py b/core/dbt/events/types.py index e236eb7a155..a8740d58c7b 100644 --- a/core/dbt/events/types.py +++ b/core/dbt/events/types.py @@ -1153,10 +1153,11 @@ def code(self): def message(self) -> str: version = ".v" + self.model_version if self.model_version else "" - return ( + msg = ( f"Model {self.model_name}{version} has passed its deprecation date of {self.deprecation_date}. " "This model should be disabled or removed." ) + return warning_tag(msg) class UpcomingReferenceDeprecation(WarnLevel): @@ -1178,7 +1179,7 @@ def message(self) -> str: ) msg = msg + coda - return msg + return warning_tag(msg) class DeprecatedReference(WarnLevel): @@ -1200,7 +1201,7 @@ def message(self) -> str: ) msg = msg + coda - return msg + return warning_tag(msg) class UnsupportedConstraintMaterialization(WarnLevel): diff --git a/core/dbt/parser/manifest.py b/core/dbt/parser/manifest.py index bb47cb51867..259413dde3d 100644 --- a/core/dbt/parser/manifest.py +++ b/core/dbt/parser/manifest.py @@ -562,7 +562,7 @@ def check_for_model_deprecations(self): node.deprecation_date and node.deprecation_date < datetime.datetime.now().astimezone() ): - fire_event( + warn_or_error( DeprecatedModel( model_name=node.name, model_version=version_to_str(node.version), @@ -581,7 +581,7 @@ def check_for_model_deprecations(self): else: event_cls = UpcomingReferenceDeprecation - fire_event( + warn_or_error( event_cls( model_name=node.name, ref_model_package=resolved_ref.package_name, diff --git a/tests/functional/deprecations/model_deprecations.py b/tests/functional/deprecations/model_deprecations.py index f57f790624b..94a67c3bfe2 100644 --- a/tests/functional/deprecations/model_deprecations.py +++ b/tests/functional/deprecations/model_deprecations.py @@ -1,6 +1,9 @@ import pytest +from dbt.exceptions import EventCompilationError from dbt.cli.main import dbtRunner +from dbt.tests.util import run_dbt + deprecated_model__yml = """ version: 2 @@ -41,6 +44,14 @@ def test_deprecation_warning(self, project): assert len(matches) == 1 assert matches[0].data.model_name == "my_model" + def test_deprecation_warning_error(self, project): + with pytest.raises(EventCompilationError): + run_dbt(["--warn-error", "parse"]) + + def test_deprecation_warning_error_options(self, project): + with pytest.raises(EventCompilationError): + run_dbt(["--warn-error-options", '{"include": ["DeprecatedModel"]}', "parse"]) + class TestReferenceDeprecatingWarning: @pytest.fixture(scope="class") @@ -59,6 +70,16 @@ def test_deprecation_warning(self, project): assert matches[0].data.model_name == "my_dependant_model" assert matches[0].data.ref_model_name == "my_model" + def test_deprecation_warning_error(self, project): + with pytest.raises(EventCompilationError): + run_dbt(["--warn-error", "parse"]) + + def test_deprecation_warning_error_options(self, project): + with pytest.raises(EventCompilationError): + run_dbt( + ["--warn-error-options", '{"include": ["UpcomingReferenceDeprecation"]}', "parse"] + ) + class TestReferenceDeprecatedWarning: @pytest.fixture(scope="class") @@ -76,3 +97,11 @@ def test_deprecation_warning(self, project): assert len(matches) == 1 assert matches[0].data.model_name == "my_dependant_model" assert matches[0].data.ref_model_name == "my_model" + + def test_deprecation_warning_error(self, project): + with pytest.raises(EventCompilationError): + run_dbt(["--warn-error", "parse"]) + + def test_deprecation_warning_error_options(self, project): + with pytest.raises(EventCompilationError): + run_dbt(["--warn-error-options", '{"include": ["DeprecatedReference"]}', "parse"])