Skip to content

Commit

Permalink
wrap deprecation warnings in warn_or_error calls (#8129) (#8137)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9765596)

Co-authored-by: Michelle Ark <MichelleArk@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and MichelleArk committed Jul 19, 2023
1 parent cf1dfaa commit a013a98
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230718-125518.yaml
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 4 additions & 3 deletions core/dbt/events/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -1178,7 +1179,7 @@ def message(self) -> str:
)
msg = msg + coda

return msg
return warning_tag(msg)


class DeprecatedReference(WarnLevel):
Expand All @@ -1200,7 +1201,7 @@ def message(self) -> str:
)
msg = msg + coda

return msg
return warning_tag(msg)


class UnsupportedConstraintMaterialization(WarnLevel):
Expand Down
4 changes: 2 additions & 2 deletions core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
Expand Down
29 changes: 29 additions & 0 deletions tests/functional/deprecations/model_deprecations.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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"])

0 comments on commit a013a98

Please sign in to comment.