Skip to content

Conversation

@y-sudharshan
Copy link

Description
This PR fixes issue #61208 where the grid view endpoint crashes with a 500 Internal Server Error when a task is converted to a TaskGroup (or vice versa) between DAG versions while historical DagRuns still exist.

Root Cause
The crash occurs in the _merge_node_dicts function within the FastAPI service layer. When a DAG structure evolves:

Historical Runs: May have a node (Task) with children=None.

Current Run: May have a node (TaskGroup) with the same ID but children=[...].

The recursive merge logic attempted to iterate over the None value from the historical run, leading to:

TypeError: 'NoneType' object is not iterable.

Changes Made
Defensive Recursion: Updated _merge_node_dicts in airflow/api_fastapi/core_api/services/ui/grid.py to handle None values by defaulting to an empty list during iteration and recursive calls.

Structural Flexibility: Enabled the grid view to gracefully handle ID collisions where a node's type changes across the DAG's lifecycle.

Testing:

Added 8 unit tests in tests/api_fastapi/core_api/services/ui/test_grid.py to validate recursive merging with mismatched types.

Added a regression integration test using the minimal DAG provided in the issue to ensure the 500 error is resolved.

Impact
Resolves the UI crash for users refactoring DAGs into TaskGroups.

Maintains backward compatibility for displaying historical runs with deprecated structures.

Checklist
[x] Code changes are covered with tests

[x] New unit test file created for service layer testing

[x] Integration test added to existing test suite

[x] Code follows existing patterns and conventions

[x] Passes all linting checks (ruff, pylint)

[x] No breaking changes

Generated-by: GitHub Copilot

Closes: #61208

@boring-cyborg
Copy link

boring-cyborg bot commented Jan 31, 2026

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@boring-cyborg boring-cyborg bot added the area:API Airflow's REST/HTTP API label Jan 31, 2026
This commit fixes a TypeError crash in the grid view endpoint when a task
is converted to a TaskGroup (or vice versa) between DAG versions.

Root Cause:
- Old DagRuns had task structure with children=None
- New DagRuns had TaskGroup structure with children=[...]
- The _merge_node_dicts function tried to iterate over None -> TypeError

Changes:
1. Added defensive None checks in _merge_node_dicts function
2. Only merge children if both nodes have children (not None)
3. Added comprehensive unit tests for edge cases
4. Added integration test for task->TaskGroup conversion scenario

Fixes apache#61208
@y-sudharshan y-sudharshan force-pushed the fix-grid-view-issue-61208 branch from 8bccca8 to 49869f4 Compare January 31, 2026 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken grid view

1 participant