Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plurals in FoundStats message #9465

Merged
merged 7 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240126-134234.yaml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 3 additions & 1 deletion core/dbt/artifacts/resources/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"


Expand Down
28 changes: 4 additions & 24 deletions core/dbt/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,14 @@
graph_file_name = "graph.gpickle"


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)

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 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, 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 ct != 0])
fire_event(FoundStats(stat_line=stat_line))


Expand All @@ -84,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):
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/minimal_cli/test_minimal_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion tests/functional/schema_tests/test_schema_v2_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_node_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading