From e47514659b4f5158ce8e26fd5c1d0e51739771e8 Mon Sep 17 00:00:00 2001 From: David Spulak Date: Tue, 17 Oct 2023 13:50:44 +0200 Subject: [PATCH 1/2] Update test - tags and config.tags to be identical (usually the case) - add consistency with has_child and is_child tag for non-test nodes --- tests/dbt/test_selector.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/dbt/test_selector.py b/tests/dbt/test_selector.py index 8e3fc8c61..20f88dcbb 100644 --- a/tests/dbt/test_selector.py +++ b/tests/dbt/test_selector.py @@ -45,7 +45,7 @@ def test_is_empty_config(selector_config, paths, tags, config, other, expected): depends_on=[], file_path=SAMPLE_PROJ_PATH / "gen1/models/grandparent.sql", tags=["has_child"], - config={"materialized": "view"}, + config={"materialized": "view", "tags": ["has_child"]}, ) parent_node = DbtNode( name="parent", @@ -53,8 +53,8 @@ def test_is_empty_config(selector_config, paths, tags, config, other, expected): resource_type=DbtResourceType.MODEL, depends_on=["grandparent"], file_path=SAMPLE_PROJ_PATH / "gen2/models/parent.sql", - tags=["has_child"], - config={"materialized": "view"}, + tags=["has_child", "is_child"], + config={"materialized": "view", "tags": ["has_child", "is_child"]}, ) child_node = DbtNode( name="child", @@ -62,8 +62,8 @@ def test_is_empty_config(selector_config, paths, tags, config, other, expected): resource_type=DbtResourceType.MODEL, depends_on=["parent"], file_path=SAMPLE_PROJ_PATH / "gen3/models/child.sql", - tags=["nightly"], - config={"materialized": "table", "tags": ["is_child"]}, + tags=["nightly", "is_child"], + config={"materialized": "table", "tags": ["nightly", "is_child"]}, ) grandchild_1_test_node = DbtNode( @@ -72,8 +72,8 @@ def test_is_empty_config(selector_config, paths, tags, config, other, expected): resource_type=DbtResourceType.MODEL, depends_on=["parent"], file_path=SAMPLE_PROJ_PATH / "gen3/models/grandchild_1.sql", - tags=["nightly"], - config={"materialized": "table", "tags": ["deprecated", "test"]}, + tags=["nightly", "deprecated", "test"], + config={"materialized": "table", "tags": ["nightly", "deprecated", "test"]}, ) grandchild_2_test_node = DbtNode( @@ -82,8 +82,8 @@ def test_is_empty_config(selector_config, paths, tags, config, other, expected): resource_type=DbtResourceType.MODEL, depends_on=["parent"], file_path=SAMPLE_PROJ_PATH / "gen3/models/grandchild_2.sql", - tags=["nightly"], - config={"materialized": "table", "tags": ["deprecated", "test2"]}, + tags=["nightly", "deprecated", "test2"], + config={"materialized": "table", "tags": ["nightly", "deprecated", "test2"]}, ) sample_nodes = { From e9f2b48007678f17215fa2e8bafb4f4901a45c12 Mon Sep 17 00:00:00 2001 From: David Spulak Date: Tue, 17 Oct 2023 14:07:26 +0200 Subject: [PATCH 2/2] Updated selector.py and related tests. --- cosmos/dbt/selector.py | 2 +- tests/dbt/test_selector.py | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cosmos/dbt/selector.py b/cosmos/dbt/selector.py index e10f5b9b2..926cc6b1a 100644 --- a/cosmos/dbt/selector.py +++ b/cosmos/dbt/selector.py @@ -106,7 +106,7 @@ def should_include_node(node_id: str, node: DbtNode) -> bool: visited_nodes.add(node_id) if config.tags: - if not (set(config.tags) == set(node.tags)): + if not (set(config.tags) <= set(node.tags)): return False node_config = {key: value for key, value in node.config.items() if key in SUPPORTED_CONFIG} diff --git a/tests/dbt/test_selector.py b/tests/dbt/test_selector.py index 20f88dcbb..9f6071a20 100644 --- a/tests/dbt/test_selector.py +++ b/tests/dbt/test_selector.py @@ -114,6 +114,7 @@ def test_select_nodes_by_select_config(): def test_select_nodes_by_select_config_tag(): selected = select_nodes(project_dir=SAMPLE_PROJ_PATH, nodes=sample_nodes, select=["config.tags:is_child"]) expected = { + parent_node.unique_id: parent_node, child_node.unique_id: child_node, } assert selected == expected @@ -146,11 +147,24 @@ def test_select_nodes_by_select_union_config_test_tags(): assert selected == expected +def test_select_nodes_by_select_intersection_tag(): + selected = select_nodes( + project_dir=SAMPLE_PROJ_PATH, nodes=sample_nodes, select=["tag:is_child,config.materialized:view"] + ) + expected = { + parent_node.unique_id: parent_node, + } + assert selected == expected + + def test_select_nodes_by_select_intersection_config_tag(): selected = select_nodes( project_dir=SAMPLE_PROJ_PATH, nodes=sample_nodes, select=["config.tags:is_child,config.materialized:view"] ) - assert selected == {} + expected = { + parent_node.unique_id: parent_node, + } + assert selected == expected def test_select_nodes_by_select_path():