From e6cacedbd714e8763e47a6aabadefeff2764bf89 Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Thu, 14 Nov 2024 15:28:18 +0100 Subject: [PATCH 1/6] Modify existing unit test --- tests/unit/test_events.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/tests/unit/test_events.py b/tests/unit/test_events.py index d6454da213c..1524b93b20d 100644 --- a/tests/unit/test_events.py +++ b/tests/unit/test_events.py @@ -18,8 +18,7 @@ TestLevel, WarnLevel, ) -from dbt.events.types import RunResultError -from dbt.task.printer import print_run_result_error +from dbt.task.printer import print_run_end_messages from dbt_common.events import types from dbt_common.events.base_types import msg_from_base_event from dbt_common.events.event_manager import EventManager, TestEventManager @@ -553,23 +552,38 @@ def test_single_run_error(): event_mgr = TestEventManager() ctx_set_event_manager(event_mgr) + class MockNode: + unique_id: str = "" + node_info = None + error_result = RunResult( status=RunStatus.Error, timing=[], thread_id="", execution_time=0.0, - node=None, + node=MockNode(), adapter_response=dict(), message="oh no!", failures=1, batch_results=None, ) - - print_run_result_error(error_result) - events = [e for e in event_mgr.event_history if isinstance(e[0], RunResultError)] - - assert len(events) == 1 - assert events[0][0].msg == "oh no!" + results = [error_result] + print_run_end_messages(results) + events = [e for e in event_mgr.event_history] + + summary_event = [ + e for e in event_mgr.event_history if isinstance(e[0], core_types.EndOfRunSummary) + ] + run_result_error_events = [ + e for e in event_mgr.event_history if isinstance(e[0], core_types.RunResultError) + ] + + # expect correct plural + assert "partial successes" in summary_event[0][0].message() + + # expect one error to show up + assert len(run_result_error_events) == 1 + assert run_result_error_events[0][0].msg == "oh no!" finally: # Set an empty event manager unconditionally on exit. This is an early From cbe747babc9d101e340fd3f8e6cf15f7636dcc2a Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Thu, 14 Nov 2024 15:28:28 +0100 Subject: [PATCH 2/6] Implement correct plural for partial success --- core/dbt/events/types.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/dbt/events/types.py b/core/dbt/events/types.py index cf5368fca0a..8a49b91155e 100644 --- a/core/dbt/events/types.py +++ b/core/dbt/events/types.py @@ -1927,9 +1927,17 @@ def code(self) -> str: return "Z030" def message(self) -> str: + + class PartialSuccess: + def __str__(self) -> str: + return "partial success" + + def pluralize(self) -> str: + return f"{self}es" + error_plural = pluralize(self.num_errors, "error") warn_plural = pluralize(self.num_warnings, "warning") - partial_success_plural = pluralize(self.num_partial_success, "partial success") + partial_success_plural = pluralize(self.num_partial_success, PartialSuccess()) if self.keyboard_interrupt: message = yellow("Exited because of keyboard interrupt") From 05c8de86284dc65d698019da04edc8673642a186 Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Thu, 14 Nov 2024 17:01:11 +0100 Subject: [PATCH 3/6] Fix integration test --- tests/functional/microbatch/test_microbatch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/microbatch/test_microbatch.py b/tests/functional/microbatch/test_microbatch.py index 3de48225f44..af004e54b41 100644 --- a/tests/functional/microbatch/test_microbatch.py +++ b/tests/functional/microbatch/test_microbatch.py @@ -603,7 +603,7 @@ def test_run_with_event_time(self, project): assert "PARTIAL SUCCESS" not in console_output assert "ERROR" in console_output - assert "Completed with 1 error, 0 partial successs, and 0 warnings" in console_output + assert "Completed with 1 error, 0 partial successes, and 0 warnings" in console_output self.assert_row_count(project, "microbatch_model", 2) @@ -612,7 +612,7 @@ def test_run_with_event_time(self, project): assert "PARTIAL SUCCESS" not in console_output assert "ERROR" in console_output - assert "Completed with 1 error, 0 partial successs, and 0 warnings" in console_output + assert "Completed with 1 error, 0 partial successes, and 0 warnings" in console_output self.assert_row_count(project, "microbatch_model", 2) From 92bfbfcd5a1b7b84499da56616faedf0e9989a9c Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Thu, 14 Nov 2024 17:03:35 +0100 Subject: [PATCH 4/6] Add changelog entry --- .changes/unreleased/Fixes-20241114-170328.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20241114-170328.yaml diff --git a/.changes/unreleased/Fixes-20241114-170328.yaml b/.changes/unreleased/Fixes-20241114-170328.yaml new file mode 100644 index 00000000000..3d1546cc594 --- /dev/null +++ b/.changes/unreleased/Fixes-20241114-170328.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fix plural of 'partial success' in log message +time: 2024-11-14T17:03:28.888232+01:00 +custom: + Author: jtcohen6 + Issue: "10999" From b6ec92da1b83e91ace45ee800272d79a0a3d8992 Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Mon, 18 Nov 2024 23:24:35 +0100 Subject: [PATCH 5/6] Simply reimplement pluralize for partial success --- core/dbt/events/types.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/core/dbt/events/types.py b/core/dbt/events/types.py index 8a49b91155e..362a43f08d9 100644 --- a/core/dbt/events/types.py +++ b/core/dbt/events/types.py @@ -1927,17 +1927,9 @@ def code(self) -> str: return "Z030" def message(self) -> str: - - class PartialSuccess: - def __str__(self) -> str: - return "partial success" - - def pluralize(self) -> str: - return f"{self}es" - error_plural = pluralize(self.num_errors, "error") warn_plural = pluralize(self.num_warnings, "warning") - partial_success_plural = pluralize(self.num_partial_success, PartialSuccess()) + partial_success_plural = f"""{self.num_partial_success} partial {"success" if self.num_partial_success == 1 else "successes"}""" if self.keyboard_interrupt: message = yellow("Exited because of keyboard interrupt") From 0f935aa0481c14233c6a1de5f73e15af4e2c0f93 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Wed, 20 Nov 2024 23:57:00 -0500 Subject: [PATCH 6/6] linting --- tests/unit/test_events.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/test_events.py b/tests/unit/test_events.py index 1524b93b20d..e3bc492aa0c 100644 --- a/tests/unit/test_events.py +++ b/tests/unit/test_events.py @@ -569,7 +569,6 @@ class MockNode: ) results = [error_result] print_run_end_messages(results) - events = [e for e in event_mgr.event_history] summary_event = [ e for e in event_mgr.event_history if isinstance(e[0], core_types.EndOfRunSummary)