-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure BaseRunner handles nodes without
build_path
Some nodes, like SourceDefinition nodes, don't have a `build_path` property. This is problematic because we take in nodes with no type checking, and assume they have properties sometimes, like `build_path`. This was just the case in BaseRunner's `_handle_generic_exception` and `_handle_interal_exception` methods. Thus to stop dbt from crashing when trying to handle an exception related to a node without a `build_path`, we added an private method to the BaseRunner class for safely trying to get `build_path`.
- Loading branch information
Showing
4 changed files
with
58 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
|
||
from dbt.artifacts.resources import Quoting, SourceConfig | ||
from dbt.artifacts.resources.types import NodeType | ||
from dbt.contracts.graph.nodes import SourceDefinition | ||
|
||
|
||
@pytest.fixture | ||
def basic_parsed_source_definition_object(): | ||
return SourceDefinition( | ||
columns={}, | ||
database="some_db", | ||
description="", | ||
fqn=["test", "source", "my_source", "my_source_table"], | ||
identifier="my_source_table", | ||
loader="stitch", | ||
name="my_source_table", | ||
original_file_path="/root/models/sources.yml", | ||
package_name="test", | ||
path="/root/models/sources.yml", | ||
quoting=Quoting(), | ||
resource_type=NodeType.Source, | ||
schema="some_schema", | ||
source_description="my source description", | ||
source_name="my_source", | ||
unique_id="test.source.my_source.my_source_table", | ||
tags=[], | ||
config=SourceConfig(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from dbt.task.base import BaseRunner | ||
from dbt.contracts.graph.nodes import SourceDefinition | ||
|
||
|
||
class MockRunner(BaseRunner): | ||
def compile(self): | ||
pass | ||
|
||
|
||
class TestBaseRunner: | ||
def test_handle_generic_exception_handles_nodes_without_build_path( | ||
self, basic_parsed_source_definition_object: SourceDefinition | ||
): | ||
# Source definition nodes don't have `build_path` attributes. Thus, this | ||
# test will fail if _handle_generic_exception doesn't account for this | ||
runner = MockRunner( | ||
config=None, | ||
adapter=None, | ||
node=basic_parsed_source_definition_object, | ||
node_index=None, | ||
num_nodes=None, | ||
) | ||
assert not hasattr(basic_parsed_source_definition_object, "build_path") | ||
runner._handle_generic_exception(Exception("bad thing happened"), ctx=None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters