Skip to content

Commit

Permalink
Include node_info in various Result events
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Mar 25, 2024
1 parent c071868 commit 915746b
Show file tree
Hide file tree
Showing 5 changed files with 754 additions and 732 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20240325-172059.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Include node_info in various Result events
time: 2024-03-25T17:20:59.445718-04:00
custom:
Author: gshank
Issue: "9619"
7 changes: 7 additions & 0 deletions core/dbt/events/core_types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,7 @@ message RunResultWarning {
string resource_type = 1;
string node_name = 2;
string path = 3;
NodeInfo node_info = 4;
}

message RunResultWarningMsg {
Expand All @@ -1784,6 +1785,7 @@ message RunResultFailure {
string resource_type = 1;
string node_name = 2;
string path = 3;
NodeInfo node_info = 4;
}

message RunResultFailureMsg {
Expand All @@ -1804,6 +1806,7 @@ message StatsLineMsg {
// Z024
message RunResultError {
string msg = 1;
NodeInfo node_info = 2;
}

message RunResultErrorMsg {
Expand All @@ -1814,6 +1817,7 @@ message RunResultErrorMsg {
// Z025
message RunResultErrorNoMessage {
string status = 1;
NodeInfo node_info = 2;
}

message RunResultErrorNoMessageMsg {
Expand All @@ -1824,6 +1828,7 @@ message RunResultErrorNoMessageMsg {
// Z026
message SQLCompiledPath {
string path = 1;
NodeInfo node_info = 2;
}

message SQLCompiledPathMsg {
Expand All @@ -1834,6 +1839,7 @@ message SQLCompiledPathMsg {
// Z027
message CheckNodeTestFailure {
string relation_name = 1;
NodeInfo node_info = 2;
}

message CheckNodeTestFailureMsg {
Expand Down Expand Up @@ -1958,6 +1964,7 @@ message TrackingInitializeFailureMsg {
// Z046
message RunResultWarningMessage {
string msg = 1;
NodeInfo node_info = 2;
}

message RunResultWarningMessageMsg {
Expand Down
1,451 changes: 725 additions & 726 deletions core/dbt/events/core_types_pb2.py

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions core/dbt/task/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ def print_run_result_error(result, newline: bool = True, is_warning: bool = Fals
fire_event(Formatting(""))

if result.status == NodeStatus.Fail or (is_warning and result.status == NodeStatus.Warn):
node_info = None
if hasattr(result, "node_info"):
node_info = result.node_info
if is_warning:
fire_event(
RunResultWarning(
resource_type=result.node.resource_type,
node_name=result.node.name,
path=result.node.original_file_path,
node_info=node_info,
)
)
else:
Expand All @@ -94,29 +98,30 @@ def print_run_result_error(result, newline: bool = True, is_warning: bool = Fals
resource_type=result.node.resource_type,
node_name=result.node.name,
path=result.node.original_file_path,
node_info=node_info,
)
)

if result.message:
if is_warning:
fire_event(RunResultWarningMessage(msg=result.message))
fire_event(RunResultWarningMessage(msg=result.message, node_info=node_info))
else:
fire_event(RunResultError(msg=result.message))
fire_event(RunResultError(msg=result.message, node_info=node_info))
else:
fire_event(RunResultErrorNoMessage(status=result.status))
fire_event(RunResultErrorNoMessage(status=result.status, node_info=node_info))

if result.node.build_path is not None:
with TextOnly():
fire_event(Formatting(""))
fire_event(SQLCompiledPath(path=result.node.compiled_path))
fire_event(SQLCompiledPath(path=result.node.compiled_path, node_info=node_info))

if result.node.should_store_failures:
with TextOnly():
fire_event(Formatting(""))
fire_event(CheckNodeTestFailure(relation_name=result.node.relation_name))
fire_event(CheckNodeTestFailure(relation_name=result.node.relation_name, node_info=node_info))

elif result.message is not None:
fire_event(RunResultError(msg=result.message))
fire_event(RunResultError(msg=result.message, node_info=node_info))


def print_run_end_messages(results, keyboard_interrupt: bool = False) -> None:
Expand Down
5 changes: 5 additions & 0 deletions core/dbt/task/runnable.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ def call_runner(self, runner: BaseRunner) -> RunResult:
if not runner.node.resource_type == NodeType.Unit:
runner.node.clear_event_status()

# In order to pass node_info into various logging events, set node_info
# as an attribute on the result, since it will be cleared out of the node.
# We don't want node_info to be serialized in the result.
setattr(result, "node_info", runner.node.node_info)

fail_fast = get_flags().FAIL_FAST

if result.status in (NodeStatus.Error, NodeStatus.Fail) and fail_fast:
Expand Down

0 comments on commit 915746b

Please sign in to comment.