From 0c96f71e64fac2fd6d024a5eaa7bcfbf46e40d05 Mon Sep 17 00:00:00 2001 From: Chenyu Li Date: Thu, 19 Dec 2024 13:00:56 -0800 Subject: [PATCH] nits --- core/dbt/artifacts/resources/v1/model.py | 6 ++---- tests/functional/artifacts/expected_manifest.py | 8 ++++++++ tests/unit/contracts/graph/test_manifest.py | 1 + tests/unit/parser/test_parser.py | 13 ++++++++++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/core/dbt/artifacts/resources/v1/model.py b/core/dbt/artifacts/resources/v1/model.py index dbc7c4d0de3..aca176ad397 100644 --- a/core/dbt/artifacts/resources/v1/model.py +++ b/core/dbt/artifacts/resources/v1/model.py @@ -36,7 +36,7 @@ class TimeSpine(dbtClassMixin): custom_granularities: List[CustomGranularity] = field(default_factory=list) -class ModelFreshnessDependsOnOptions(enum.StrEnum): +class ModelFreshnessDependsOnOptions(enum.Enum): all = "all" any = "any" @@ -50,9 +50,7 @@ class ModelBuildAfter(Time): @dataclass class ModelFreshness(dbtClassMixin): - build_after: ModelBuildAfter = field( - default_factory=lambda: ModelBuildAfter(period=TimePeriod.hour, count=0) - ) + build_after: ModelBuildAfter = field(default_factory=ModelBuildAfter) @dataclass diff --git a/tests/functional/artifacts/expected_manifest.py b/tests/functional/artifacts/expected_manifest.py index d11c1e567a0..02db1905443 100644 --- a/tests/functional/artifacts/expected_manifest.py +++ b/tests/functional/artifacts/expected_manifest.py @@ -372,6 +372,7 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): "version": None, "latest_version": None, "time_spine": None, + "freshness": None, }, "model.test.second_model": { "compiled_path": os.path.join(compiled_model_path, "second_model.sql"), @@ -471,6 +472,7 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): "version": None, "latest_version": None, "time_spine": None, + "freshness": None, }, "seed.test.seed": { "build_path": None, @@ -1003,6 +1005,7 @@ def expected_references_manifest(project): "latest_version": None, "constraints": [], "time_spine": None, + "freshness": None, }, "model.test.ephemeral_summary": { "alias": "ephemeral_summary", @@ -1075,6 +1078,7 @@ def expected_references_manifest(project): "latest_version": None, "constraints": [], "time_spine": None, + "freshness": None, }, "model.test.view_summary": { "alias": "view_summary", @@ -1143,6 +1147,7 @@ def expected_references_manifest(project): "latest_version": None, "constraints": [], "time_spine": None, + "freshness": None, }, "seed.test.seed": { "alias": "seed", @@ -1609,6 +1614,7 @@ def expected_versions_manifest(project): "version": 1, "latest_version": 2, "time_spine": None, + "freshness": None, }, "model.test.versioned_model.v2": { "alias": "versioned_model_v2", @@ -1680,6 +1686,7 @@ def expected_versions_manifest(project): "version": 2, "latest_version": 2, "time_spine": None, + "freshness": None, }, "model.test.ref_versioned_model": { "alias": "ref_versioned_model", @@ -1738,6 +1745,7 @@ def expected_versions_manifest(project): "version": None, "latest_version": None, "time_spine": None, + "freshness": None, }, "test.test.unique_versioned_model_v1_first_name.6138195dec": { "alias": "unique_versioned_model_v1_first_name", diff --git a/tests/unit/contracts/graph/test_manifest.py b/tests/unit/contracts/graph/test_manifest.py index 3505ee80037..526f46c7884 100644 --- a/tests/unit/contracts/graph/test_manifest.py +++ b/tests/unit/contracts/graph/test_manifest.py @@ -97,6 +97,7 @@ "defer_relation", "time_spine", "batch", + "freshness", } ) diff --git a/tests/unit/parser/test_parser.py b/tests/unit/parser/test_parser.py index 2921d19af0b..d6b2d53655f 100644 --- a/tests/unit/parser/test_parser.py +++ b/tests/unit/parser/test_parser.py @@ -8,7 +8,10 @@ from dbt import tracking from dbt.artifacts.resources import ModelConfig, RefArgs -from dbt.artifacts.resources.v1.model import ModelBuildAfter +from dbt.artifacts.resources.v1.model import ( + ModelBuildAfter, + ModelFreshnessDependsOnOptions, +) from dbt.context.context_config import ContextConfig from dbt.contracts.files import FileHash, FilePath, SchemaSourceFile, SourceFile from dbt.contracts.graph.manifest import Manifest @@ -728,7 +731,9 @@ def test__parse_model_freshness(self): assert self.parser.manifest.nodes[ "model.root.my_model" - ].freshness.build_after == ModelBuildAfter(count=1, period="day", depends_on="any") + ].freshness.build_after == ModelBuildAfter( + count=1, period="day", depends_on=ModelFreshnessDependsOnOptions.any + ) def test__parse_model_freshness_depend_on(self): block = self.file_block_for(SINGLE_TALBE_MODEL_FRESHNESS_ONLY_DEPEND_ON, "test_one.yml") @@ -738,7 +743,9 @@ def test__parse_model_freshness_depend_on(self): self.assert_has_manifest_lengths(self.parser.manifest, nodes=1) assert self.parser.manifest.nodes[ "model.root.my_model" - ].freshness.build_after == ModelBuildAfter(count=0, period="hour", depends_on="all") + ].freshness.build_after == ModelBuildAfter( + count=0, period="hour", depends_on=ModelFreshnessDependsOnOptions.all + ) def test__read_basic_model_tests_wrong_severity(self): block = self.yaml_block_for(SINGLE_TABLE_MODEL_TESTS_WRONG_SEVERITY, "test_one.yml")