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 error counts for exposures #11207

Merged
merged 1 commit into from
Jan 10, 2025
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
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20250110-202057.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Fix error counts for exposures
time: 2025-01-10T20:20:57.01632Z
custom:
Author: aranke
Issue: ' '
20 changes: 13 additions & 7 deletions core/dbt/task/printer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Dict, Optional, Union

from dbt.artifacts.schemas.results import NodeStatus
from dbt.contracts.graph.nodes import Exposure
from dbt.events.types import (
CheckNodeTestFailure,
EndOfRunSummary,
Expand Down Expand Up @@ -83,7 +84,9 @@
node_info = None
if hasattr(result, "node") and result.node:
node_info = result.node.node_info
if result.status == NodeStatus.Fail or (is_warning and result.status == NodeStatus.Warn):
if result.status in (NodeStatus.Fail, NodeStatus.Error) or (
is_warning and result.status == NodeStatus.Warn
):
if newline:
fire_event(Formatting(""))
if is_warning:
Expand Down Expand Up @@ -115,11 +118,11 @@
else:
fire_event(RunResultErrorNoMessage(status=result.status, node_info=node_info))

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

if result.node.should_store_failures:
if getattr(result.node, "should_store_failures", None):
fire_event(Formatting(""))
fire_event(
CheckNodeTestFailure(relation_name=result.node.relation_name, node_info=node_info)
Expand All @@ -139,10 +142,13 @@
for r in results:
if r.status in (NodeStatus.RuntimeErr, NodeStatus.Error, NodeStatus.Fail):
errors.append(r)
elif r.status == NodeStatus.Skipped and r.message is not None:
# this means we skipped a node because of an issue upstream,
# so include it as an error
errors.append(r)
elif r.status == NodeStatus.Skipped and r.message:
if isinstance(r.node, Exposure):
# Don't include exposure skips in errors list
continue

Check warning on line 148 in core/dbt/task/printer.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/task/printer.py#L148

Added line #L148 was not covered by tests
else:
# This means we skipped a node because of an issue upstream, so include it as an error
errors.append(r)
elif r.status == NodeStatus.Warn:
warnings.append(r)
elif r.status == NodeStatus.PartialSuccess:
Expand Down
28 changes: 14 additions & 14 deletions core/dbt/task/runnable.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from dbt.cli.flags import Flags
from dbt.config.runtime import RuntimeConfig
from dbt.contracts.graph.manifest import Manifest
from dbt.contracts.graph.nodes import ResultNode
from dbt.contracts.graph.nodes import Exposure, ResultNode
from dbt.contracts.state import PreviousState
from dbt.events.types import (
ArtifactWritten,
Expand Down Expand Up @@ -619,19 +619,19 @@ def interpret_results(cls, results):
if results is None:
return False

failures = [
r
for r in results
if r.status
in (
NodeStatus.RuntimeErr,
NodeStatus.Error,
NodeStatus.Fail,
NodeStatus.Skipped, # propogate error message causing skip
NodeStatus.PartialSuccess, # because partial success also means partial failure
)
]
return len(failures) == 0
num_runtime_errors = len([r for r in results if r.status == NodeStatus.RuntimeErr])
num_errors = len([r for r in results if r.status == NodeStatus.Error])
num_fails = len([r for r in results if r.status == NodeStatus.Fail])
num_skipped = len(
[
r
for r in results
if r.status == NodeStatus.Skipped and not isinstance(r.node, Exposure)
]
)
num_partial_success = len([r for r in results if r.status == NodeStatus.PartialSuccess])
num_total = num_runtime_errors + num_errors + num_fails + num_skipped + num_partial_success
return num_total == 0

def get_model_schemas(self, adapter, selected_uids: Iterable[str]) -> Set[BaseRelation]:
if self.manifest is None:
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,9 @@ def test_single_run_error():
class MockNode:
unique_id: str = ""
node_info = None
resource_type: str = "model"
name: str = "my_model"
original_file_path: str = "path/to/model.sql"

error_result = RunResult(
status=RunStatus.Error,
Expand Down
Loading