Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] raise execution errors for runnable tasks #8237

Merged
merged 3 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question, do we want to always do pool.close() , pool.join() before join? If yes, based on the document that finally will be executed before break, return, continue, should we consider just write it as

try:
  xxxx
  return  self.node_results
except:
  xxxx
finally:
  pool.close()
  pool.join()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That may be a very sound thing to do, but I think the safest path forward to ensure the regression (and any others that may be lingering) are fixed is to go back to the state before this change: https://github.com/dbt-labs/dbt-core/pull/8066/files#diff-f01af78b7eaa1bacc301afa75eea4c7cdbe03064b3913bc2ce3f6bf01d0bc125R383-R386, where there was no finally

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverts the changes made here: https://github.com/dbt-labs/dbt-core/pull/8066/files#diff-4f5f78d9b3b6f6eda81916de152b5c17b9d1ef14e40b7a2031c4d10f601d6474L210-L211

On closer inspection, I'm not sure why this test was modified, it is a change in behaviour for non fail-fast functionality.

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