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

   ## What's the problem?
   
   `TIRescheduleStatePayload` was the only intermediate-state payload missing 
`rendered_map_index`. As a result, when a mapped sensor sets 
`context["map_index_template"]` inside its `poke()` body and then raises 
`AirflowRescheduleException` to reschedule, the `rendered_map_index` value is 
never persisted to the database. The UI displays the raw integer `map_index` 
(e.g. `0`, `1`) on every `up_for_reschedule` row instead of the human-readable 
rendered label.
   
   The final successful poke **does** show the rendered label (because the 
success path already serialises `rendered_map_index` via `TaskState`), so the 
column appears intermittently.
   
   Fixes #67521
   
   ## Root cause
   
   The full data path for a reschedule is:
   
   ```
   sensor.poke()
     ↓ raises AirflowRescheduleException
   task_runner.run()
     ↓ except AirflowRescheduleException: builds RescheduleTask(…)   ← missing 
rendered_map_index
   supervisor._handle_requests()
     ↓ client.task_instances.reschedule(id, msg)                      ← msg has 
no rendered_map_index
   execution API PATCH /task-instances/{id}
     ↓ TIRescheduleStatePayload                                       ← model 
had no field
     ↓ query.values(state=…, next_method=None, next_kwargs=None)      ← 
_rendered_map_index never written
   ```
   
   All other intermediate states (`TIDeferredStatePayload`, 
`TIAwaitingInputStatePayload`, `TIRetryStatePayload`, `TITerminalStatePayload`, 
`TISuccessStatePayload`) already carry `rendered_map_index`. The reschedule 
path was the only one left out.
   
   Note: `_render_map_index()` **is** called in the `except Exception:` block 
(line ~1576 of `task_runner.py`) before re-raising 
`AirflowRescheduleException`, so `ti.rendered_map_index` is correctly populated 
by the time we build `RescheduleTask`. We only need to pass it through.
   
   ## Changes
   
   | File | Change |
   |------|--------|
   | `airflow-core/…/datamodels/taskinstance.py` | Add `rendered_map_index: str 
\| None = None` to `TIRescheduleStatePayload` (server-side model) |
   | `task-sdk/…/api/datamodels/_generated.py` | Same field on the client-side 
generated model |
   | `task-sdk/…/execution_time/task_runner.py` | Pass 
`rendered_map_index=ti.rendered_map_index` when constructing `RescheduleTask` |
   | `task-sdk/…/execution_time/supervisor.py` | Set `self._rendered_map_index 
= msg.rendered_map_index` in both `RescheduleTask` handler branches |
   | `airflow-core/…/routes/task_instances.py` | Include 
`_rendered_map_index=ti_patch_payload.rendered_map_index` in the 
`UP_FOR_RESCHEDULE` query |
   | `airflow-core/…/versions/v2026_06_30.py` | Cadwyn migration 
`AddRenderedMapIndexToReschedulePayload` |
   | `airflow-core/…/versions/__init__.py` | Register the migration in the 
`2026-06-30` version bundle |
   | `task-sdk/tests/…/test_task_runner.py` | Regression test 
`test_run_reschedule_includes_rendered_map_index` |
   
   ## Testing
   
   New regression test verifies that when a sensor sets `map_index_template` 
and rescheduled, the `RescheduleTask` message carries `rendered_map_index`:
   
   ```python
   def test_run_reschedule_includes_rendered_map_index(create_runtime_ti, 
mock_supervisor_comms):
       ...
       assert msg.rendered_map_index is not None
   ```
   


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