Skip to content

Commit 4b693a6

Browse files
committed
Add examples of using +tag:some_tag that work
1 parent 3ca1d51 commit 4b693a6

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

cosmos/dbt/selector.py

-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ def select_nodes(
498498
exclude = exclude or []
499499
if not select and not exclude:
500500
return nodes
501-
502501
validate_filters(exclude, select)
503502
subset_ids = apply_select_filter(nodes, project_dir, select)
504503
if select:

tests/dbt/test_selector.py

+35-9
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,6 @@ def test_is_empty_config(selector_config, paths, tags, config, other, expected):
6464
config={"materialized": "view", "tags": ["has_child", "is_child"]},
6565
)
6666

67-
parent_sibling_node = DbtNode(
68-
unique_id=f"{DbtResourceType.MODEL.value}.{SAMPLE_PROJ_PATH.stem}.parent_sibling",
69-
resource_type=DbtResourceType.MODEL,
70-
depends_on=[grandparent_node.unique_id, another_grandparent_node.unique_id],
71-
file_path=SAMPLE_PROJ_PATH / "gen2/models/parent_sibling.sql",
72-
tags=["is_adopted"],
73-
config={"materialized": "view", "tags": ["is_adopted"]},
74-
)
7567

7668
child_node = DbtNode(
7769
unique_id=f"{DbtResourceType.MODEL.value}.{SAMPLE_PROJ_PATH.stem}.child",
@@ -208,11 +200,45 @@ def test_select_nodes_by_select_intersection_config_graph_selector_none():
208200
assert selected == expected
209201

210202

203+
def test_select_nodes_by_intersection_and_tag_ancestry():
204+
parent_sibling_node = DbtNode(
205+
unique_id=f"{DbtResourceType.MODEL.value}.{SAMPLE_PROJ_PATH.stem}.parent_sibling",
206+
resource_type=DbtResourceType.MODEL,
207+
depends_on=[grandparent_node.unique_id, another_grandparent_node.unique_id],
208+
file_path=SAMPLE_PROJ_PATH / "gen2/models/parent_sibling.sql",
209+
tags=["is_adopted"],
210+
config={"materialized": "view", "tags": ["is_adopted"]},
211+
)
212+
sample_nodes_with_parent_sibling = dict(sample_nodes)
213+
sample_nodes_with_parent_sibling[parent_sibling_node.unique_id] = parent_sibling_node
214+
selected = select_nodes(
215+
project_dir=SAMPLE_PROJ_PATH, nodes=sample_nodes_with_parent_sibling, select=["+tag:is_child,+tag:is_adopted"]
216+
)
217+
expected = {
218+
grandparent_node.unique_id: grandparent_node,
219+
another_grandparent_node.unique_id: another_grandparent_node,
220+
}
221+
assert selected == expected
222+
223+
211224
def test_select_nodes_by_tag_ancestry():
212-
selected = select_nodes(project_dir=SAMPLE_PROJ_PATH, nodes=sample_nodes, select=["+tag:is_child,+tag:is_adopted"])
225+
parent_sibling_node = DbtNode(
226+
unique_id=f"{DbtResourceType.MODEL.value}.{SAMPLE_PROJ_PATH.stem}.parent_sibling",
227+
resource_type=DbtResourceType.MODEL,
228+
depends_on=[grandparent_node.unique_id, another_grandparent_node.unique_id],
229+
file_path=SAMPLE_PROJ_PATH / "gen2/models/parent_sibling.sql",
230+
tags=["is_adopted"],
231+
config={"materialized": "view", "tags": ["is_adopted"]},
232+
)
233+
sample_nodes_with_parent_sibling = dict(sample_nodes)
234+
sample_nodes_with_parent_sibling[parent_sibling_node.unique_id] = parent_sibling_node
235+
selected = select_nodes(
236+
project_dir=SAMPLE_PROJ_PATH, nodes=sample_nodes_with_parent_sibling, select=["+tag:is_adopted"]
237+
)
213238
expected = {
214239
grandparent_node.unique_id: grandparent_node,
215240
another_grandparent_node.unique_id: another_grandparent_node,
241+
parent_sibling_node.unique_id: parent_sibling_node,
216242
}
217243
assert selected == expected
218244

0 commit comments

Comments
 (0)