Skip to content
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 @@ -334,7 +334,7 @@ def __init__(
execution_mode=execution_config.execution_mode,
task_args=task_args,
test_indirect_selection=execution_config.test_indirect_selection,
dbt_project_name=render_config.project_name,
dbt_project_name=render_config.project_name or project_config.project_name,
on_warning_callback=on_warning_callback,
render_config=render_config,
async_py_requirements=execution_config.async_py_requirements,
Expand Down
44 changes: 44 additions & 0 deletions tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,50 @@ def test_converter_creates_dag_with_test_with_multiple_parents_test_afterall():
assert multiple_parents_test_test_args[1:] == ["test"]


@pytest.mark.integration
def test_converter_creates_dag_with_after_all_test_uses_project_name_from_project_config():
"""
Validate that when using LoadMode.DBT_MANIFEST with project_name set in ProjectConfig
but no dbt_project_path in RenderConfig, the test task name uses project_config.project_name
instead of falling back to an empty string.
"""
project_config = ProjectConfig(manifest_path=SAMPLE_DBT_MANIFEST, project_name="jaffle_shop")
execution_config = ExecutionConfig(
execution_mode=ExecutionMode.LOCAL,
dbt_project_path=SAMPLE_DBT_PROJECT, # Required for execution, but not used for project_name
Comment thread
tatiana marked this conversation as resolved.
)
render_config = RenderConfig(
test_behavior=TestBehavior.AFTER_ALL,
load_method=LoadMode.DBT_MANIFEST,
# Note: dbt_project_path is NOT set, so render_config.project_name will be empty
)
profile_config = ProfileConfig(
profile_name="test",
target_name="test",
profile_mapping=PostgresUserPasswordProfileMapping(conn_id="test", profile_args={}),
)
with DAG("sample_dag", start_date=datetime(2024, 4, 16)) as dag:
DbtToAirflowConverter(
dag=dag,
project_config=project_config,
profile_config=profile_config,
execution_config=execution_config,
render_config=render_config,
)

# Find the test task created with AFTER_ALL behavior
test_tasks = [task for task in dag.tasks if task.task_id.endswith("_test")]
assert len(test_tasks) == 1, "Expected exactly one test task with AFTER_ALL behavior"
test_task = test_tasks[0]

# Verify the test task name uses project_config.project_name instead of empty string
assert test_task.task_id == "jaffle_shop_test", (
f"Expected test task name to be 'jaffle_shop_test' but got '{test_task.task_id}'. "
"This validates that dbt_project_name falls back to project_config.project_name "
"when render_config.project_name is empty."
)


@pytest.mark.integration
def test_converter_creates_dag_with_test_with_multiple_parents_test_none():
"""
Expand Down