From f088f4b544ef1c43f4fa967a1d71987763fd16fc Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Tue, 7 Jan 2025 12:31:19 -0500 Subject: [PATCH 1/3] use UndefinedMacroError instead of DbtInternalError when macro not found --- core/dbt/task/run_operation.py | 3 +-- tests/functional/run_operations/test_run_operations.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/core/dbt/task/run_operation.py b/core/dbt/task/run_operation.py index f87ac63e04e..c2b39b3870d 100644 --- a/core/dbt/task/run_operation.py +++ b/core/dbt/task/run_operation.py @@ -19,7 +19,6 @@ from dbt.node_types import NodeType from dbt.task.base import ConfiguredTask from dbt_common.events.functions import fire_event -from dbt_common.exceptions import DbtInternalError RESULT_FILE_NAME = "run_results.json" @@ -86,7 +85,7 @@ def run(self) -> RunResultsArtifact: unique_id = macro.unique_id fqn = unique_id.split(".") else: - raise DbtInternalError( + raise dbt_common.exceptions.macros.UndefinedMacroError( f"dbt could not find a macro with the name '{macro_name}' in any package" ) diff --git a/tests/functional/run_operations/test_run_operations.py b/tests/functional/run_operations/test_run_operations.py index 258ed679d7e..8799bb2705c 100644 --- a/tests/functional/run_operations/test_run_operations.py +++ b/tests/functional/run_operations/test_run_operations.py @@ -13,7 +13,7 @@ run_dbt_and_capture, write_file, ) -from dbt_common.exceptions import DbtInternalError +from dbt_common.exceptions.macros import UndefinedMacroError from tests.functional.run_operations.fixtures import ( happy_macros_sql, model_sql, @@ -81,7 +81,7 @@ def test_macro_exception(self, project): def test_macro_missing(self, project): with pytest.raises( - DbtInternalError, + UndefinedMacroError, match="dbt could not find a macro with the name 'this_macro_does_not_exist' in any package", ): self.run_operation("this_macro_does_not_exist", False) From 90f0e613c11ab577f0efc8f9ad7b6cb4da1b6003 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Tue, 7 Jan 2025 12:40:09 -0500 Subject: [PATCH 2/3] changelog entry --- .changes/unreleased/Under the Hood-20250107-123955.yaml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changes/unreleased/Under the Hood-20250107-123955.yaml diff --git a/.changes/unreleased/Under the Hood-20250107-123955.yaml b/.changes/unreleased/Under the Hood-20250107-123955.yaml new file mode 100644 index 00000000000..b819b38b4f5 --- /dev/null +++ b/.changes/unreleased/Under the Hood-20250107-123955.yaml @@ -0,0 +1,7 @@ +kind: Under the Hood +body: Change exception type from DbtInternalException to UndefinedMacroError when + macro not found in 'run operation' command +time: 2025-01-07T12:39:55.234321-05:00 +custom: + Author: michelleark + Issue: "11192" From 1ad9ca41a75621f4ca710593a214ee37161c484f Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Tue, 7 Jan 2025 16:14:48 -0500 Subject: [PATCH 3/3] simplify imports --- core/dbt/task/run_operation.py | 2 +- tests/functional/run_operations/test_run_operations.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/dbt/task/run_operation.py b/core/dbt/task/run_operation.py index c2b39b3870d..fb71597dbf2 100644 --- a/core/dbt/task/run_operation.py +++ b/core/dbt/task/run_operation.py @@ -85,7 +85,7 @@ def run(self) -> RunResultsArtifact: unique_id = macro.unique_id fqn = unique_id.split(".") else: - raise dbt_common.exceptions.macros.UndefinedMacroError( + raise dbt_common.exceptions.UndefinedMacroError( f"dbt could not find a macro with the name '{macro_name}' in any package" ) diff --git a/tests/functional/run_operations/test_run_operations.py b/tests/functional/run_operations/test_run_operations.py index 8799bb2705c..eef66bec8a6 100644 --- a/tests/functional/run_operations/test_run_operations.py +++ b/tests/functional/run_operations/test_run_operations.py @@ -13,7 +13,7 @@ run_dbt_and_capture, write_file, ) -from dbt_common.exceptions.macros import UndefinedMacroError +from dbt_common.exceptions import UndefinedMacroError from tests.functional.run_operations.fixtures import ( happy_macros_sql, model_sql,