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 invalid argument (full_refresh) passed to DbtTestAwsEksOperator (and others) #1175

Merged
merged 6 commits into from
Sep 21, 2024
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
1 change: 1 addition & 0 deletions cosmos/operators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def __init__(
self.dbt_cmd_global_flags = dbt_cmd_global_flags or []
self.cache_dir = cache_dir
self.extra_context = extra_context or {}
kwargs.pop("full_refresh", None) # usage of this param should be implemented in child classes
super().__init__(**kwargs)

def get_env(self, context: Context) -> dict[str, str | bytes | os.PathLike[Any]]:
Expand Down
1 change: 0 additions & 1 deletion cosmos/operators/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ def __init__(
self._dbt_runner: dbtRunner | None = None
if self.invocation_mode:
self._set_invocation_methods()
kwargs.pop("full_refresh", None) # usage of this param should be implemented in child classes
super().__init__(**kwargs)

# For local execution mode, we're consistent with the LoadMode.DBT_LS command in forwarding the environment
Expand Down
65 changes: 65 additions & 0 deletions tests/operators/test_kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,68 @@ def test_created_pod():
]
assert container.args == expected_container_args
assert container.command == []


@pytest.mark.parametrize(
"operator_class,kwargs,expected_cmd",
[
(
DbtSeedKubernetesOperator,
{"full_refresh": True},
["dbt", "seed", "--full-refresh", "--project-dir", "my/dir"],
),
(
DbtBuildKubernetesOperator,
{"full_refresh": True},
["dbt", "build", "--full-refresh", "--project-dir", "my/dir"],
),
(
DbtRunKubernetesOperator,
{"full_refresh": True},
["dbt", "run", "--full-refresh", "--project-dir", "my/dir"],
),
(
DbtTestKubernetesOperator,
{},
["dbt", "test", "--project-dir", "my/dir"],
),
(
DbtTestKubernetesOperator,
{"select": []},
["dbt", "test", "--project-dir", "my/dir"],
),
(
DbtTestKubernetesOperator,
{"full_refresh": True, "select": ["tag:daily"], "exclude": ["tag:disabled"]},
["dbt", "test", "--select", "tag:daily", "--exclude", "tag:disabled", "--project-dir", "my/dir"],
),
(
DbtTestKubernetesOperator,
{"full_refresh": True, "selector": "nightly_snowplow"},
["dbt", "test", "--selector", "nightly_snowplow", "--project-dir", "my/dir"],
),
],
)
def test_operator_execute_with_flags(operator_class, kwargs, expected_cmd):
task = operator_class(
task_id="my-task",
project_dir="my/dir",
**kwargs,
)

with patch(
"airflow.providers.cncf.kubernetes.operators.pod.KubernetesPodOperator.hook",
is_in_cluster=False,
), patch("airflow.providers.cncf.kubernetes.operators.pod.KubernetesPodOperator.cleanup"), patch(
"airflow.providers.cncf.kubernetes.operators.pod.KubernetesPodOperator.get_or_create_pod",
side_effect=ValueError("Mock"),
) as get_or_create_pod:
try:
task.execute(context={})
except ValueError as e:
if e != get_or_create_pod.side_effect:
raise

pod_args = get_or_create_pod.call_args.kwargs["pod_request_obj"].to_dict()["spec"]["containers"][0]["args"]

assert expected_cmd == pod_args
Loading