Skip to content

Commit

Permalink
[Fix] raise execution errors for runnable tasks (#8237)
Browse files Browse the repository at this point in the history
(cherry picked from commit 410506f)
  • Loading branch information
MichelleArk authored and github-actions[bot] committed Jul 28, 2023
1 parent 2b00544 commit 6f100de
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20230728-115620.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Fixes
body: Ensure runtime errors are raised for graph runnable tasks (compile, show, run,
etc)
time: 2023-07-28T11:56:20.863718-04:00
custom:
Author: michelleark
Issue: "8166"
12 changes: 7 additions & 5 deletions core/dbt/task/runnable.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,17 @@ def execute_nodes(self):
)

print_run_result_error(failure.result)
raise
# ensure information about all nodes is propagated to run results when failing fast
return self.node_results
except KeyboardInterrupt:
self._cancel_connections(pool)
print_run_end_messages(self.node_results, keyboard_interrupt=True)
raise
finally:
pool.close()
pool.join()
return self.node_results

pool.close()
pool.join()

return self.node_results

def _mark_dependent_errors(self, node_id, result, cause):
if self.graph is None:
Expand Down
4 changes: 4 additions & 0 deletions tests/functional/compile/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ def test_inline_fail(self, project):
with pytest.raises(DbtException, match="Error parsing inline query"):
run_dbt(["compile", "--inline", "select * from {{ ref('third_model') }}"])

def test_inline_fail_database_error(self, project):
with pytest.raises(DbtRuntimeError, match="Database Error"):
run_dbt(["show", "--inline", "slect asdlkjfsld;j"])

def test_multiline_jinja(self, project):
(results, log_output) = run_dbt_and_capture(["compile", "--inline", model_multiline_jinja])
assert len(results) == 1
Expand Down
6 changes: 2 additions & 4 deletions tests/functional/dependencies/test_local_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import dbt.semver
import dbt.config
import dbt.exceptions
from dbt.contracts.results import RunStatus

from dbt.tests.util import check_relations_equal, run_dbt, run_dbt_and_capture

Expand Down Expand Up @@ -208,9 +207,8 @@ def models(self):

def test_missing_dependency(self, project):
# dbt should raise a runtime exception
res = run_dbt(["compile"], expect_pass=False)
assert len(res) == 1
assert res[0].status == RunStatus.Error
with pytest.raises(dbt.exceptions.DbtRuntimeError):
run_dbt(["compile"])


class TestSimpleDependencyWithSchema(BaseDependencyTest):
Expand Down
5 changes: 4 additions & 1 deletion tests/functional/show/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ def test_inline_pass(self, project):
assert "sample_bool" in log_output

def test_inline_fail(self, project):
run_dbt(["build"])
with pytest.raises(DbtException, match="Error parsing inline query"):
run_dbt(["show", "--inline", "select * from {{ ref('third_model') }}"])

def test_inline_fail_database_error(self, project):
with pytest.raises(DbtRuntimeError, match="Database Error"):
run_dbt(["show", "--inline", "slect asdlkjfsld;j"])

def test_ephemeral_model(self, project):
run_dbt(["build"])
(results, log_output) = run_dbt_and_capture(["show", "--select", "ephemeral_model"])
Expand Down

0 comments on commit 6f100de

Please sign in to comment.