From 2a28ef1f0763e5143295bc4ca1062cfd9d5eb96d Mon Sep 17 00:00:00 2001 From: Tatiana Al-Chueyr Date: Wed, 27 Sep 2023 21:28:31 +0100 Subject: [PATCH] Change specific to release 1.1.2 - to be reverted after #561 is closed (cherry picked from commit 1483fd45c1555f5fc5305dd8ed868c7793b21a34) --- cosmos/operators/local.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cosmos/operators/local.py b/cosmos/operators/local.py index 52428753e..b6d0d12c8 100644 --- a/cosmos/operators/local.py +++ b/cosmos/operators/local.py @@ -42,8 +42,10 @@ ) from cosmos.dbt.parser.output import extract_log_issues, parse_output -logger = get_logger(__name__) +DBT_NO_TESTS_MSG = "Nothing to do" +DBT_WARN_MSG = "WARN" +logger = get_logger(__name__) try: from airflow.providers.openlineage.extractors.base import OperatorLineage @@ -473,12 +475,18 @@ def _handle_warnings(self, result: FullOutputSubprocessResult, context: Context) warning_context["test_names"] = test_names warning_context["test_results"] = test_results - if self.on_warning_callback: - self.on_warning_callback(warning_context) + self.on_warning_callback and self.on_warning_callback(warning_context) def execute(self, context: Context) -> None: result = self.build_and_run_cmd(context=context) - if self.on_warning_callback and "WARN" in result.output: + should_trigger_callback = all( + [ + self.on_warning_callback, + DBT_NO_TESTS_MSG not in result.output, + DBT_WARN_MSG in result.output, + ] + ) + if should_trigger_callback: warnings = parse_output(result, "WARN") if warnings > 0: self._handle_warnings(result, context)