From b6aa8bc87b6b3dd60bfa2ec86ca467b78b66e7be Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Fri, 26 Jan 2024 13:35:30 +0100 Subject: [PATCH 1/6] Pluralize object instead of string --- core/dbt/compilation.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/dbt/compilation.py b/core/dbt/compilation.py index c84ffe11be1..dbbe0cb31a5 100644 --- a/core/dbt/compilation.py +++ b/core/dbt/compilation.py @@ -71,8 +71,7 @@ def print_compile_stats(stats): dbt.tracking.track_resource_counts(resource_counts) # do not include resource types that are not actually defined in the project - stat_line = ", ".join([pluralize(ct, names.get(t)) for t, ct in stats.items() if t in names]) - + stat_line = ", ".join([pluralize(ct, t) for t, ct in stats.items() if t in names]) fire_event(FoundStats(stat_line=stat_line)) From 36e0f4495920947e51881dfddb7d97238f6c9563 Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Fri, 26 Jan 2024 13:36:56 +0100 Subject: [PATCH 2/6] Refactor print_compile_stats --- core/dbt/compilation.py | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/core/dbt/compilation.py b/core/dbt/compilation.py index dbbe0cb31a5..3b88f28deb3 100644 --- a/core/dbt/compilation.py +++ b/core/dbt/compilation.py @@ -46,32 +46,13 @@ def print_compile_stats(stats): - names = { - NodeType.Model: "model", - NodeType.Test: "data test", - NodeType.Unit: "unit test", - NodeType.Snapshot: "snapshot", - NodeType.Analysis: "analysis", - NodeType.Macro: "macro", - NodeType.Operation: "operation", - NodeType.Seed: "seed", - NodeType.Source: "source", - NodeType.Exposure: "exposure", - NodeType.SemanticModel: "semantic model", - NodeType.Metric: "metric", - NodeType.Group: "group", - } - - results = {k: 0 for k in names.keys()} - results.update(stats) - # create tracking event for resource_counts if dbt.tracking.active_user is not None: - resource_counts = {k.pluralize(): v for k, v in results.items()} + resource_counts = {k.pluralize(): v for k, v in stats.items()} dbt.tracking.track_resource_counts(resource_counts) # do not include resource types that are not actually defined in the project - stat_line = ", ".join([pluralize(ct, t) for t, ct in stats.items() if t in names]) + stat_line = ", ".join([pluralize(ct, t) for t, ct in stats.items() if ct != 0]) fire_event(FoundStats(stat_line=stat_line)) From 8f3869d8fd2a61f64ec7398cc8a4b3ce8bae0de1 Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Fri, 26 Jan 2024 13:42:40 +0100 Subject: [PATCH 3/6] Add changie entry --- .changes/unreleased/Fixes-20240126-134234.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20240126-134234.yaml diff --git a/.changes/unreleased/Fixes-20240126-134234.yaml b/.changes/unreleased/Fixes-20240126-134234.yaml new file mode 100644 index 00000000000..1d38d339490 --- /dev/null +++ b/.changes/unreleased/Fixes-20240126-134234.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fix node type plurals in FoundStats log message +time: 2024-01-26T13:42:34.651033+01:00 +custom: + Author: jtcohen6 + Issue: "9464" From d24b209ed52c3b398dd1d0613f9059e4f1827b0b Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Fri, 26 Jan 2024 11:16:45 -0500 Subject: [PATCH 4/6] type annotations --- core/dbt/compilation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/dbt/compilation.py b/core/dbt/compilation.py index 3b88f28deb3..207d973acf6 100644 --- a/core/dbt/compilation.py +++ b/core/dbt/compilation.py @@ -45,7 +45,7 @@ graph_file_name = "graph.gpickle" -def print_compile_stats(stats): +def print_compile_stats(stats: Dict[NodeType, int]): # create tracking event for resource_counts if dbt.tracking.active_user is not None: resource_counts = {k.pluralize(): v for k, v in stats.items()} @@ -64,7 +64,7 @@ def _node_enabled(node: ManifestNode): return True -def _generate_stats(manifest: Manifest): +def _generate_stats(manifest: Manifest) -> Dict[NodeType, int]: stats: Dict[NodeType, int] = defaultdict(int) for node in manifest.nodes.values(): if _node_enabled(node): From d398c9603e54b3c7e418014bc1072b8805d99bf2 Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Sun, 28 Jan 2024 13:41:36 +0100 Subject: [PATCH 5/6] The plural of NodeType.Test is 'data_tests' --- core/dbt/artifacts/resources/types.py | 4 +++- tests/functional/minimal_cli/test_minimal_cli.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/dbt/artifacts/resources/types.py b/core/dbt/artifacts/resources/types.py index 447142881a8..f86ca8a26af 100644 --- a/core/dbt/artifacts/resources/types.py +++ b/core/dbt/artifacts/resources/types.py @@ -18,7 +18,7 @@ def is_valid(cls, item): class NodeType(StrEnum): Model = "model" Analysis = "analysis" - Test = "test" + Test = "test" # renamed to 'data_test'; preserved as 'test' here for back-compat Snapshot = "snapshot" Operation = "operation" Seed = "seed" @@ -41,6 +41,8 @@ def pluralize(self) -> str: return "analyses" elif self is self.SavedQuery: return "saved_queries" + elif self is self.Test: + return "data_tests" return f"{self}s" diff --git a/tests/functional/minimal_cli/test_minimal_cli.py b/tests/functional/minimal_cli/test_minimal_cli.py index d47f8b911c5..8408354df78 100644 --- a/tests/functional/minimal_cli/test_minimal_cli.py +++ b/tests/functional/minimal_cli/test_minimal_cli.py @@ -35,7 +35,7 @@ def test_ls(self, runner, project): ls_result = runner.invoke(cli, ["ls"]) assert "1 seed" in ls_result.output assert "1 model" in ls_result.output - assert "5 data tests" in ls_result.output + assert "5 data_tests" in ls_result.output assert "1 snapshot" in ls_result.output From 19ed794424527f2478d9a68ec74f46ef73ed87e4 Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Mon, 29 Jan 2024 01:23:56 +0100 Subject: [PATCH 6/6] Fix failing tests --- tests/functional/schema_tests/test_schema_v2_tests.py | 2 +- tests/unit/test_node_types.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/schema_tests/test_schema_v2_tests.py b/tests/functional/schema_tests/test_schema_v2_tests.py index af85bcc290c..34286d82532 100644 --- a/tests/functional/schema_tests/test_schema_v2_tests.py +++ b/tests/functional/schema_tests/test_schema_v2_tests.py @@ -906,7 +906,7 @@ def test_generic_test_collision( """These tests collide, since only the configs differ""" with pytest.raises(DuplicateResourceNameError) as exc: run_dbt() - assert "dbt found two tests with the name" in str(exc.value) + assert "dbt found two data_tests with the name" in str(exc.value) class TestGenericTestsConfigCustomMacros: diff --git a/tests/unit/test_node_types.py b/tests/unit/test_node_types.py index e9b5d1bae82..9611429a934 100644 --- a/tests/unit/test_node_types.py +++ b/tests/unit/test_node_types.py @@ -4,7 +4,7 @@ node_type_pluralizations = { NodeType.Model: "models", NodeType.Analysis: "analyses", - NodeType.Test: "tests", + NodeType.Test: "data_tests", NodeType.Snapshot: "snapshots", NodeType.Operation: "operations", NodeType.Seed: "seeds",