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

   When setting task instance or task group state on a DAG run that has no 
`logical_date` (manual or asset-triggered runs), passing `include_past` or 
`include_future` caused downstream task clearing to cross run boundaries. This 
inadvertently cleared failed tasks in other runs of the same DAG and could push 
them back into queued state.
   
   Since past and future runs are undefined without a `logical_date`, the UI 
already disables these toggles and the clear-task API rejects them with a 400. 
This PR brings the mark-state routes to parity by rejecting the combination 
upfront with HTTP 400 instead of executing cross-run clears.
   
   ### What changed
   
   - **API validation**: Added early validation for single TI and task group 
PATCH / dry-run requests before locking or DB mutation.
   - **Bulk handling**: Validates entities upfront using a cached DagRun lookup 
per run to avoid N+1 queries. Invalid entities are recorded in bulk errors and 
filtered out of `valid_entities`, so they cannot participate in run locking or 
expand downstream selections in regional or non-regional paths.
   - **Model guard**: `SerializedDAG.set_task_instance_state` and 
`set_task_group_state` validate this condition and raise `ValueError` before 
clearing downstream tasks, which the API maps to a 400.
   - Shared canonical validation helper and error message across API and model 
layers.
   
   ### Breaking change note
   
   This is only breaking for clients sending `include_past` or `include_future` 
on runs without a `logical_date`. Those requests previously returned 200 while 
silently corrupting task states across unrelated runs; they now properly fail 
with 400.
   
   ### Test plan
   
   - Single TI on manual run + `include_past`/`future` returns 400; tasks in 
dated run remain intact.
   - Single TI on manual run without flags updates normally (200).
   - Single TI on dated run + `include_future` succeeds (200).
   - Dry-run TI and task group return 400 when flags are set on a run without 
`logical_date`.
   - Bulk requests with invalid entities return 200 with per-item 400 errors 
and do not clear other runs.
   - Bulk requests with mixed valid and invalid entities (including duplicate 
entries for the same task) apply valid updates, reject invalid ones, and leave 
other runs untouched.
   - Unit tests verify `SerializedDAG` raises `ValueError` for both single TI 
and task group state setters.
   
   closes: #75134
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes
   <!--
   -->
   


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