Skip to content

Fix clearTaskInstances API: Restore include_past/future support on UI - #54416

Merged
pierrejeambrun merged 14 commits into
apache:mainfrom
bggwak:fix/54134
Sep 4, 2025
Merged

pierrejeambrun merged 14 commits into
apache:mainfrom
bggwak:fix/54134

Conversation

@bggwak

@bggwak bggwak commented Aug 12, 2025

Copy link
Copy Markdown
Contributor

This PR resolves the issue reported in #54134, where attempting to clear task instances from the Airflow UI using both dag_run_id and include_past/include_future resulted in a 400 error. This prevented users from clearing past or future task instances via the UI, which was possible in previous Airflow versions.

With this fix:

The API now correctly allows the use of include_past/include_future together with dag_run_id, as long as the DAG run has a valid logical_date (i.e., for scheduled DAG runs).
For manually triggered DAG runs (where logical_date is None), the API still returns a 400 error to protect against accidental clearing of unrelated task instances—preventing the original bug from resurfacing.

closes: #54134

스크린샷 2025-08-12 오후 11 36 53

@boring-cyborg

boring-cyborg Bot commented Aug 12, 2025

Copy link
Copy Markdown

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 pre-commits 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 Aug 12, 2025

@pierrejeambrun pierrejeambrun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thanks.

A few comments to address before we can merge.

Also I just started the CI and it will need fixing (code formatting etc...)

Comment thread airflow-core/src/airflow/api_fastapi/core_api/routes/public/task_instances.py Outdated
Comment thread airflow-core/src/airflow/api_fastapi/core_api/routes/public/task_instances.py Outdated
Comment thread airflow-core/src/airflow/api_fastapi/core_api/routes/public/task_instances.py Outdated
Comment thread airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_instances.py Outdated
Comment thread airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_instances.py Outdated
Comment thread airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_instances.py Outdated
Comment thread airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_instances.py Outdated
@bggwak

bggwak commented Aug 20, 2025

Copy link
Copy Markdown
Contributor Author

@pierrejeambrun
Thanks for the review!
I’ve addressed all the feedback
All review comments should now be resolved

@pierrejeambrun pierrejeambrun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please fix the CI?

Tested locally, looks good. Just a few things to adjust, we can merge then.

Comment thread airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_instances.py Outdated
Comment thread airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_instances.py Outdated
Comment thread airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_task_instances.py Outdated
Comment thread airflow-core/src/airflow/api_fastapi/core_api/routes/public/task_instances.py Outdated

@pierrejeambrun pierrejeambrun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thanks

@pierrejeambrun

Copy link
Copy Markdown
Member

Not directly related to this PR, but we need to fix the cache invalidation in the front-end request when clearing a Task.

We can see on the 'grid' that the 'TI' state is updated while clearing, but the associated Run remain in its final state, instead of being 'running' and also future/past can impact other dag runs so we should invalidate Grid data for tasks and runs of the entire grid, if these parameters are provided.

That could be a nice follow up. @nothingmin

@pierrejeambrun

Copy link
Copy Markdown
Member
Screenshot 2025-09-04 at 17 03 53

While it should be like this after the clearing request:
Screenshot 2025-09-04 at 17 04 06

@pierrejeambrun

Copy link
Copy Markdown
Member

Issue here #55267

@pierrejeambrun
pierrejeambrun merged commit f5d0b17 into apache:main Sep 4, 2025
107 checks passed
@boring-cyborg

boring-cyborg Bot commented Sep 4, 2025

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

@github-actions

github-actions Bot commented Sep 4, 2025

Copy link
Copy Markdown
Contributor

Backport failed to create: v3-0-test. View the failure log Run details

Status Branch Result
❌ v3-0-test Commit Link

You can attempt to backport this manually by running:

cherry_picker f5d0b17 v3-0-test

This should apply the commit to the v3-0-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

@pierrejeambrun

Copy link
Copy Markdown
Member

Manual backport #55272

pierrejeambrun added a commit that referenced this pull request Sep 5, 2025
…#54416) (#55272)

Co-authored-by: Gwak Beomgyu <67548026+nothingmin@users.noreply.github.com>
RoyLee1224 pushed a commit to RoyLee1224/airflow that referenced this pull request Sep 8, 2025
…apache#54416)

* Fix clearTaskInstances API: Restore include_past/include_future support on UI

* style: fix formatting

* chore: fix typo

* chore: remove comment

* chore: fix comment DX to TX

* refactor: remove verbose handling future or past

* refactor: remove verbose handling future or past

* refactor: use hardcoded test result

* fix(test_task_instances.py): correct test comment

* fix(test_task_instances.py): fix typo

* fix(test_task_instances.py): fix typo

* fix(task_instances.py): make sure start_date, end_date to None

* fix(task_instances.py): fix inaccurate response

* fix(task_instances.py): fix inaccurate response

---------

Co-authored-by: bggwak <bggwak@hyundai.com>
@kaxil kaxil modified the milestones: Airflow 3.0.7, Airflow 3.1.0 Sep 13, 2025
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.

Airflow 3 Clear Task Instance for past or future doesn't work

4 participants