Skip to content

Commit

Permalink
use is_past_deprecation_date in more places + add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed May 24, 2024
1 parent 326a887 commit 0ebff00
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 15 deletions.
20 changes: 8 additions & 12 deletions core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,25 +570,21 @@ def safe_update_project_parser_files_partially(self, project_parser_files: Dict)

def check_for_model_deprecations(self):
for node in self.manifest.nodes.values():
if isinstance(node, ModelNode):
if (
node.deprecation_date
and node.deprecation_date < datetime.datetime.now().astimezone()
):
warn_or_error(
DeprecatedModel(
model_name=node.name,
model_version=version_to_str(node.version),
deprecation_date=node.deprecation_date.isoformat(),
)
if isinstance(node, ModelNode) and node.is_past_deprecation_date:
warn_or_error(
DeprecatedModel(
model_name=node.name,
model_version=version_to_str(node.version),
deprecation_date=node.deprecation_date.isoformat(),
)
)

resolved_refs = self.manifest.resolve_refs(node, self.root_project.project_name)
resolved_model_refs = [r for r in resolved_refs if isinstance(r, ModelNode)]
node.depends_on
for resolved_ref in resolved_model_refs:
if resolved_ref.deprecation_date:
if resolved_ref.deprecation_date < datetime.datetime.now().astimezone():
if resolved_ref.is_past_deprecation_date:

Check warning on line 587 in core/dbt/parser/manifest.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/parser/manifest.py#L587

Added line #L587 was not covered by tests
event_cls = DeprecatedReference
else:
event_cls = UpcomingReferenceDeprecation
Expand Down
53 changes: 50 additions & 3 deletions tests/unit/graph/test_nodes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from copy import deepcopy
from datetime import datetime
from typing import List

import pytest
Expand All @@ -8,11 +9,19 @@
DimensionType,
EntityType,
)

from dbt.artifacts.resources import Defaults, Dimension, Entity, Measure, TestMetadata
from freezegun import freeze_time

from dbt.artifacts.resources import (
Defaults,
Dimension,
Entity,
FileHash,
Measure,
TestMetadata,
)
from dbt.artifacts.resources.v1.semantic_model import NodeRelation
from dbt.contracts.graph.model_config import TestConfig
from dbt.contracts.graph.nodes import ColumnInfo, SemanticModel
from dbt.contracts.graph.nodes import ColumnInfo, ModelNode, SemanticModel
from dbt.node_types import NodeType
from dbt_common.contracts.constraints import (
ColumnLevelConstraint,
Expand All @@ -22,6 +31,44 @@
from tests.unit.fixtures import generic_test_node, model_node


class TestModelNode:
@pytest.fixture(scope="class")
def default_model_node(self):
return ModelNode(
resource_type=NodeType.Model,
unique_id="model.test_package.test_name",
name="test_name",
package_name="test_package",
schema="test_schema",
alias="test_alias",
fqn=["models", "test_name"],
original_file_path="test_original_file_path",
checksum=FileHash.from_contents("checksum"),
path="test_path",
database=None,
)

@pytest.mark.parametrize(
"deprecation_date,current_date,expected_is_past_deprecation_date",
[
(None, "2024-05-02", False),
("2024-05-01", "2024-05-02", True),
("2024-05-01", "2024-05-01", False),
("2024-05-01", "2024-04-30", False),
],
)
def test_is_past_deprecation_date(
self, default_model_node, deprecation_date, current_date, expected_is_past_deprecation_date
):
with freeze_time(current_date):
if deprecation_date is not None:
default_model_node.deprecation_date = datetime.strptime(
deprecation_date, "%Y-%m-%d"
).astimezone()

assert default_model_node.is_past_deprecation_date is expected_is_past_deprecation_date


class TestSemanticModel:
@pytest.fixture(scope="function")
def dimensions(self) -> List[Dimension]:
Expand Down

0 comments on commit 0ebff00

Please sign in to comment.