Add option to collapse TaskGroups by default in Graph View
- Dominant language
- Python
- Stars
- 46.9k
- Forks
- 17.8k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 483
Description
### Description
In the current Airflow Graph View, all TaskGroups are expanded by default when a DAG is opened.
For very large DAGs, this makes the view cluttered and difficult to navigate.
For smaller DAGs or selected TaskGroups, it is convenient to see the details immediately.
It would be very helpful to have:
1. A DAG-level parameter to set the default collapse state for all TaskGroups in that DAG.
2. A TaskGroup-level parameter to override the default for specific groups.
### Use case/motivation
- **Large DAGs**: collapsing TaskGroups by default improves readability and reduces visual clutter.
- **Mixed DAGs**: some TaskGroups should start collapsed (big ones), while others should stay expanded (small utility groups).
- This dual control (global default + per-group override) gives DAG authors maximum flexibility.
### Proposed solution
Introduce:
- `taskgroup_collapsed` as an optional argument in the DAG constructor (default = False).
- `collapsed` as an optional argument in `TaskGroup(...)` (default = None → inherit from DAG setting).
#### Example
```python
from airflow import DAG
from airflow.utils.task_group import TaskGroup
from airflow.operators.empty import EmptyOperator
from datetime import datetime
with DAG(
dag_id="my_dag",
default_args={"owner": "airflow"},
start_date=datetime(2025, 1, 1),
schedule_interval="@daily",
taskgroup_collapsed=True, # NEW DAG-level default
) as dag:
# This group will be collapsed by default (inherits from DAG)
with TaskGroup(group_id="processing", tooltip="Data processing") as processing:
t1 = EmptyOperator(task_id="start")
t2 = EmptyOperator(task_id="end")
t1 >> t2
# This group explicitly overrides the default
with TaskGroup(group_id="small", tooltip="Tiny group", collapsed=False) as small_group:
EmptyOperator(task_id="only_task")
### Related issues
[AIP-38: Add Expand/Collapse all task groups button](https://github.com/apache/airflow/issues/47429?utm_source=chatgpt.com)
– request for a global toggle in the UI.
[Task expand/collapse is intermittently available in grid view](https://github.com/apache/airflow/issues/53919?utm_source=chatgpt.com)
– describes inconsistent collapse/expand behavior.
[Add UI collapse property to TaskGroups](https://github.com/apache/airflow/issues/19773?utm_source=chatgpt.com)
– earlier proposal for a collapse initial state (closed but highly relevant).
### Are you willing to submit a PR?
- [ ] Yes I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
Contributor guide
Research direction
Start by tracing the Graph View's TaskGroup expansion behavior, then inspect the DAG constructor and TaskGroup entry points described in the issue. Add the DAG-level default and per-TaskGroup override, preserving inheritance when no override is supplied. Done means large DAGs can open collapsed by default while individual groups can remain expanded, with existing behavior unchanged by default.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-engineering, frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 62/100