Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ def _project_child_deps(
self, child_idx: int, child: DAGNode, id_to_idx: dict[str, int]
) -> tuple[int, ...]:
upstream_ids = child.upstream_task_ids
if isinstance(child, SerializedTaskGroup):
root_upstream_ids = set()
for root_task in child.get_roots():
root_upstream_ids.update(root_task.upstream_task_ids)
upstream_ids = upstream_ids | root_upstream_ids
if not upstream_ids:
return ()
sib_deps: set[int] = set()
Expand Down
25 changes: 25 additions & 0 deletions airflow-core/tests/unit/utils/test_task_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,31 @@ def nested_topo(group):
]


def test_topological_sort_serialized_task_level_cross_group_dep():
"""Task-level deps between groups are respected for ordering after serialization.

When a task inside group_b depends on a task inside group_a, the serialized
topological sort must place group_a before group_b.
"""
with DAG("test_cross_group_task_dep", schedule=None, start_date=DEFAULT_DATE) as dag:
with TaskGroup("stage_b"):
b_start = EmptyOperator(task_id="b_start")
b_end = EmptyOperator(task_id="b_end")
b_start >> b_end

with TaskGroup("stage_a"):
a_start = EmptyOperator(task_id="a_start")
a_end = EmptyOperator(task_id="a_end")
a_start >> a_end

b_end >> a_start

serialized = create_scheduler_dag(dag)
order = [node.node_id for node in serialized.task_group.topological_sort()]

assert order.index("stage_b") < order.index("stage_a")


def test_topological_sort_serialized_layered():
"""SerializedTaskGroup.topological_sort emits a valid order after DAG round-trip.

Expand Down