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 instantiating DbtTaskGroup with argument dag (outside of DAG context) #916

Merged
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
2 changes: 1 addition & 1 deletion cosmos/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def airflow_kwargs(**kwargs: dict[str, Any]) -> dict[str, Any]:
new_kwargs = {}
non_airflow_kwargs = specific_kwargs(**kwargs)
for arg_key, arg_value in kwargs.items():
if arg_key not in non_airflow_kwargs:
if arg_key not in non_airflow_kwargs or arg_key == "dag":
new_kwargs[arg_key] = arg_value
return new_kwargs

Expand Down
26 changes: 26 additions & 0 deletions tests/airflow/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
TestBehavior,
TestIndirectSelection,
)
from cosmos.converter import airflow_kwargs
from cosmos.dbt.graph import DbtNode
from cosmos.profiles import PostgresUserPasswordProfileMapping

Expand Down Expand Up @@ -431,3 +432,28 @@ def test_create_test_task_metadata(node_type, node_unique_id, test_indirect_sele
)
def test_snake_case_to_camelcase(input, expected):
assert _snake_case_to_camelcase(input) == expected


def test_airflow_kwargs_generation():
"""
airflow_kwargs_generation should always contain dag.
"""
task_args = {
"group_id": "fake_group_id",
"project_dir": SAMPLE_PROJ_PATH,
"conn_id": "fake_conn",
"render_config": RenderConfig(select=["fake-render"]),
"default_args": {"retries": 2},
"profile_config": ProfileConfig(
profile_name="default",
target_name="default",
profile_mapping=PostgresUserPasswordProfileMapping(
conn_id="fake_conn",
profile_args={"schema": "public"},
),
),
"dag": DAG(dag_id="fake_dag_name"),
}
result = airflow_kwargs(**task_args)

assert "dag" in result
Loading