anzinmhd opened a new pull request, #75931:
URL: https://github.com/apache/airflow/pull/75931

   Deleting a Dag run can leave its latest-run information and task-count 
badges visible on the Dags list until the browser is refreshed. This PR 
invalidates the queries supplying that information after deletion and prevents 
previous task counts from remaining visible when a Dag has no runs left.
   
   ### Problem
   
   After deleting a completed Dag run and returning to the Dags list through UI 
navigation, the Dag card can still show information about the deleted run, 
including its Latest Run timestamp and task-count badges.
   
   The backend deletes the run successfully. The frontend continues displaying 
cached results until they are refreshed. A browser refresh removes the stale 
information.
   
   ### Cause
   
   Two frontend cache behaviors contribute to the problem:
   
   1. **Deletion does not invalidate the Dag-card queries.**  
      Both single-run and bulk-run deletion invalidate several run and task 
queries, but omit the queries supplying the Dags list, run-state counts, and 
recent task-state counts. Returning to the list can therefore reuse cached 
results describing the deleted run.
   
   2. **Deleting the last run can leave previous task counts visible.**  
      `useRecentTaskStateCounts` retains previous results as placeholder data. 
When no run IDs remain, the query is disabled, but the hook can still expose 
those previous results to the Dag card.
   
   Invalidating the queries addresses stale cached results, but the last-run 
case also requires excluding task-count entries that no longer correspond to a 
Dag with runs.
   
   ### Fix
   
   Both `useDeleteDagRun` and `useBulkDeleteDagRuns` now invalidate:
   
   - The Dags list query.
   - The Dag run-state counts query.
   - The recent task-instance state counts query.
   
   The deletion flow awaits these invalidations before invoking its success 
callback. Active queries can refetch, while inactive cached queries are marked 
stale so they refresh when used again.
   
   `useRecentTaskStateCounts` also filters its returned entries against the 
Dags whose current list data contains runs. This prevents previous or 
placeholder task counts from remaining visible after a Dag’s last run is 
deleted, including when other Dags on the page still have runs.
   
   No backend or API changes are required.
   
   ### Steps to reproduce
   
   1. Use a manually triggered Dag with a completed run and visible task-count 
badges.
   2. Open the Dags list and note the card’s Latest Run timestamp and 
task-count badges.
   3. Open the completed run using its Latest Run link.
   4. Delete the Dag run and confirm deletion.
   5. Return to the Dags list using UI navigation, without refreshing the 
browser.
   6. Inspect the Dag card.
   7. Refresh the browser and compare the displayed information.
   
   Deleting the Dag’s only run makes the stale-data behavior especially clear.
   
   **Before:** The card can retain the deleted run’s Latest Run information and 
task-count badges. Refreshing the browser removes the stale information.
   
   **After:** Returning to the list loads updated run information without 
requiring a browser refresh. When no runs remain, the deleted run’s task-count 
badges are no longer displayed.
   
   ### Version and scope
   
   - Reproduced on a local development checkout of `main`.
   - Before-and-after recordings document the single-run deletion workflow.
   - Automated regression coverage includes both single-run and bulk-run 
deletion.
   - Beta and released versions have not been independently verified.
   - This change addresses stale information after deletion. It does not change 
task-count polling while runs are completing.
   
   ### Tests and validation
   
   Added eight regression cases covering:
   
   - Invalidation of each of the three Dag-card query families after single-run 
deletion.
   - Invalidation of those same query families after bulk-run deletion.
   - Removal of previous task-count entries after deleting a Dag’s last run, 
both with and without another Dag that still has runs.
   
   Validation completed:
   
   - All eight new regression cases fail without the corresponding production 
changes.
   - All **11 tests across the two focused test files pass**.
   - The broader verification run passed **143 tests across 18 files**, 
covering the deletion hooks, Dag-list queries and components, and Dag Runs.
   - Targeted ESLint checks pass.
   - Targeted Prettier checks pass.
   - TypeScript checking passes.
   - The UI production build passes.
   
   The broader test run emitted a socket warning but exited successfully.
   
   ### Before
   
   After deleting the run and returning to the Dags list, the card retains 
information about the deleted run. A browser refresh removes it.
   
   
https://github.com/user-attachments/assets/490bbba2-2679-4978-bd30-8a09899de1b3
   
   ### After
   
   After deleting the run and returning to the Dags list, the card updates 
without a browser refresh and no longer displays the deleted run’s information 
and task-count badges.
   
   
https://github.com/user-attachments/assets/1ec82334-9e36-4c0e-9788-13684834964a
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Codex (GPT-6)


-- 
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]

Reply via email to