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 running dbt tests that depend on multiple models (support --indirect-selection buildable) #613

Merged
merged 7 commits into from
Oct 23, 2023
1 change: 1 addition & 0 deletions cosmos/airflow/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def create_test_task_metadata(
"""
task_args = dict(task_args)
task_args["on_warning_callback"] = on_warning_callback
task_args["indirect_selection"] = "buildable"
if node is not None:
if node.resource_type == DbtResourceType.MODEL:
task_args["models"] = node.name
Expand Down
5 changes: 5 additions & 0 deletions cosmos/operators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def __init__(
vars: dict[str, str] | None = None,
models: str | None = None,
emit_datasets: bool = True,
indirect_selection: str | None = None,
cache_selected_only: bool = False,
no_version_check: bool = False,
fail_fast: bool = False,
Expand All @@ -115,6 +116,7 @@ def __init__(
self.vars = vars
self.models = models
self.emit_datasets = emit_datasets
self.indirect_selection = indirect_selection
self.cache_selected_only = cache_selected_only
self.no_version_check = no_version_check
self.fail_fast = fail_fast
Expand Down Expand Up @@ -213,6 +215,9 @@ def build_cmd(
if self.base_cmd:
dbt_cmd.extend(self.base_cmd)

if self.indirect_selection:
dbt_cmd += ["--indirect-selection", self.indirect_selection]

dbt_cmd.extend(self.add_global_flags())

# add command specific flags
Expand Down
7 changes: 6 additions & 1 deletion tests/airflow/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,9 @@ def test_create_test_task_metadata(node_type, node_unique_id, selector_key, sele
)
assert metadata.id == "test_no_nulls"
assert metadata.operator_class == "cosmos.operators.local.DbtTestLocalOperator"
assert metadata.arguments == {"task_arg": "value", "on_warning_callback": True, selector_key: selector_value}
assert metadata.arguments == {
"task_arg": "value",
"indirect_selection": "buildable",
"on_warning_callback": True,
selector_key: selector_value,
}
Loading