Copilot commented on code in PR #69248:
URL: https://github.com/apache/airflow/pull/69248#discussion_r3527361134


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -643,21 +643,22 @@ def _create_ti_state_update_query_and_update_state(
             if ti is not None:
                 _handle_fail_fast_for_dag(ti=ti, dag_id=dag_id, 
session=session, dag_bag=dag_bag)
         elif isinstance(ti_patch_payload, TIRetryStatePayload):
+            retry_delay_override = ti_patch_payload.retry_delay_seconds
+            retry_reason = ti_patch_payload.retry_reason[:500] if 
ti_patch_payload.retry_reason else None
             if ti is not None:
-                # Set the overrides on the TI *before* archiving so record_ti()
-                # snapshots them into task_instance_history (it copies attrs 
off
-                # the ti object). Otherwise the per-try audit trail is always 
NULL.
-                ti.retry_delay_override = ti_patch_payload.retry_delay_seconds
-                ti.retry_reason = (
-                    ti_patch_payload.retry_reason[:500] if 
ti_patch_payload.retry_reason else None
-                )
+                # Snapshot the finished try onto the TI *before* archiving so 
record_ti()
+                # copies the values into task_instance_history (it reads attrs 
off the
+                # ti object and cannot see the live-row UPDATE built below).
+                ti.retry_delay_override = retry_delay_override
+                ti.retry_reason = retry_reason
+                ti.end_date = ti_patch_payload.end_date
+                ti.set_duration()
+                if ti_patch_payload.rendered_map_index is not None:
+                    ti._rendered_map_index = 
ti_patch_payload.rendered_map_index

Review Comment:
   In the retry path, `rendered_map_index` is only copied onto the in-memory TI 
when it is not `None`. If a client explicitly sends `"rendered_map_index": 
null` (field present but cleared), the live-row UPDATE will set 
`_rendered_map_index` to NULL (due to `exclude_unset=True` handling earlier), 
but the archived `task_instance_history.rendered_map_index` will still snapshot 
the previous value from the TI object. To keep TIH consistent with what the 
worker sent, set `_rendered_map_index` whenever the field is present in the 
payload, even if it is `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