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 adding test nodes to DAGs built using LoadMethod.DBT_MANIFEST and LoadMethod.CUSTOM #615

Merged
merged 15 commits into from
Oct 30, 2023
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
3 changes: 3 additions & 0 deletions cosmos/dbt/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ def should_include_node(node_id: str, node: DbtNode) -> bool:

visited_nodes.add(node_id)

if node.resource_type == DbtResourceType.TEST:
node.tags = getattr(nodes.get(node.depends_on[0]), "tags", [])

if config.tags:
if not (set(config.tags) <= set(node.tags)):
return False
Expand Down
20 changes: 20 additions & 0 deletions tests/dbt/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,26 @@ def test_update_node_dependency_test_not_exist():
assert nodes.has_test is False


def test_tag_selected_node_test_exist():
project_config = ProjectConfig(
dbt_project_path=DBT_PROJECTS_ROOT_DIR / DBT_PROJECT_NAME, manifest_path=SAMPLE_MANIFEST
)
profile_config = ProfileConfig(
profile_name="test",
target_name="test",
profiles_yml_filepath=DBT_PROJECTS_ROOT_DIR / DBT_PROJECT_NAME / "profiles.yml",
)
dbt_graph = DbtGraph(project=project_config, profile_config=profile_config, select=["tag:test_tag"])
dbt_graph.load_from_dbt_manifest()

assert len(dbt_graph.filtered_nodes) > 0

for _, node in dbt_graph.filtered_nodes.items():
tatiana marked this conversation as resolved.
Show resolved Hide resolved
assert node.tags == ["test_tag"]
if node.resource_type == DbtResourceType.MODEL:
assert node.has_test is True


@pytest.mark.integration
@pytest.mark.parametrize("load_method", ["load_via_dbt_ls", "load_from_dbt_manifest"])
def test_load_dbt_ls_and_manifest_with_model_version(load_method):
Expand Down
8 changes: 6 additions & 2 deletions tests/sample/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7576,7 +7576,9 @@
"resource_type": "model",
"schema": "public",
"sources": [],
"tags": [],
"tags": [
"test_tag"
],
"unique_id": "model.jaffle_shop.customers",
"unrendered_config": {
"materialized": "table"
Expand Down Expand Up @@ -7754,7 +7756,9 @@
"resource_type": "model",
"schema": "public",
"sources": [],
"tags": [],
"tags": [
"test_tag"
],
"unique_id": "model.jaffle_shop.orders",
"unrendered_config": {
"materialized": "table"
Expand Down
Loading