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" diff --git a/core/dbt/task/run_operation.py b/core/dbt/task/run_operation.py index f87ac63e04e..fb71597dbf2 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.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..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 import DbtInternalError +from dbt_common.exceptions 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)