steveahnahn opened a new pull request, #68423:
URL: https://github.com/apache/airflow/pull/68423
Reduce task-group query work in the Execution API.
The task-instance count and state endpoints now resolve task-group task IDs
from the serialized Dag and apply those IDs to the task-instance query before
executing it. This avoids loading task-instance rows just to build another
filter, and avoids the `/states` task-group path fetching Dag-wide task
instances before replacing that result with the group rows.
Why:
- `/execution/task-instances/states?task_group_id=...` executed one broad
`task_instance` SELECT and one group-scoped `task_instance` SELECT.
- `/execution/task-instances/count?task_group_id=...` loaded group
task-instance rows before executing the count query.
- The serialized Dag already contains the task IDs needed to apply the group
filter directly.
What changed:
- Replace the row-loading task-group helper with a task-ID helper.
- Apply task-group task IDs directly in the count query.
- Build one task-id filter for `/states`, preserving the union of explicit
`task_ids` and task-group tasks.
- Add regression assertions that each task-group request performs a single
`task_instance` SELECT.
Evidence:
- Reproduction before fix:
- `breeze run pytest
airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py::TestGetCount::test_get_count_with_task_group
airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py::TestGetTaskStates::test_get_task_states_group_id_basic
-q`
- Before the source change, both tests failed with `AssertionError: assert
2 == 1`.
- Regression test passing after fix:
- `breeze run pytest
airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py::TestGetCount::test_get_count_with_task_group
airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py::TestGetTaskStates::test_get_task_states_group_id_basic
-q`
- `2 passed`
- Broader focused tests:
- `breeze run pytest
airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py::TestGetCount
airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py::TestGetTaskStates
-q`
- `40 passed`
- Static checks:
- `.venv/bin/uv run ruff check --fix
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py
airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py`
- `.venv/bin/uv run ruff format --check
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py
airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py`
- `PATH=.venv/bin:$PATH prek run --files
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py
airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py
--stage pre-commit`
- `PATH=.venv/bin:$PATH prek run --files
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py
airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py
--stage manual`
##### Was generative AI tooling used to co-author this PR?
- [X] Yes - Codex (GPT-5)
Generated-by: Codex (GPT-5) following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]