Skip to content
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
2 changes: 1 addition & 1 deletion cosmos/dbt/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def _should_include_node(self, node_id: str, node: DbtNode) -> bool:

self.visited_nodes.add(node_id)

if node.resource_type == DbtResourceType.TEST and node.depends_on:
if node.resource_type == DbtResourceType.TEST and node.depends_on and len(node.depends_on) > 0:
node.tags = getattr(self.nodes.get(node.depends_on[0]), "tags", [])
logger.debug(
"The test node <%s> inherited these tags from the parent node <%s>: %s",
Expand Down
16 changes: 15 additions & 1 deletion tests/dbt/test_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from cosmos.constants import DbtResourceType
from cosmos.dbt.graph import DbtNode
from cosmos.dbt.selector import SelectorConfig, select_nodes
from cosmos.dbt.selector import NodeSelector, SelectorConfig, select_nodes
from cosmos.exceptions import CosmosValueError

SAMPLE_PROJ_PATH = Path("/home/user/path/dbt-proj/")
Expand Down Expand Up @@ -418,3 +418,17 @@ def test_node_without_depends_on_with_tag_selector_should_not_raise_exception():
)
nodes = {standalone_test_node.unique_id: standalone_test_node}
assert not select_nodes(project_dir=SAMPLE_PROJ_PATH, nodes=nodes, select=["tag:some-tag"])


def test_should_include_node_without_depends_on(selector_config):
node = DbtNode(
unique_id=f"{DbtResourceType.TEST.value}.{SAMPLE_PROJ_PATH.stem}.standalone",
resource_type=DbtResourceType.TEST,
depends_on=None,
tags=[],
config={},
file_path=SAMPLE_PROJ_PATH / "tests/generic/builtin.sql",
)
selector = NodeSelector({}, selector_config)
selector.visited_nodes = set()
selector._should_include_node(node.unique_id, node)