dheerajturaga commented on code in PR #71425:
URL: https://github.com/apache/airflow/pull/71425#discussion_r4209233212


##########
airflow-core/src/airflow/models/taskinstance.py:
##########
@@ -1245,6 +1239,9 @@ def complete_restart(self, *, session: Session) -> 
TaskInstance:
         if self.state != TaskInstanceState.RESTARTING or self.working_set is 
not True:
             raise ValueError("Only a current restarting task instance can 
complete a restart")
         successor = self.prepare_db_for_next_try(session)
+        # Keep the terminated attempt's version; the successor follows the 
run's current code.
+        if dag_version_id := DBDagBag._version_from_dag_run(self.dag_run, 
session=session):
+            successor.dag_version_id = dag_version_id

Review Comment:
   **Minor, and fine to handle in a follow-up PR; it doesn't block this one.**
   
   When a run has been moved to a newer version, the successor now gets that 
version's `dag_version_id`. Both callers of `complete_restart` set `self.task` 
from `get_dag_for_run(ti.dag_run)`, so `max_tries` follows the new version too.
   
   The other task-derived columns don't follow it. `prepare_db_for_next_try` 
copies `queue`, `pool`, `pool_slots`, `priority_weight`, `executor`, 
`executor_config`, `run_as_user` and `operator` from the terminated attempt's 
row. `schedule_tis` only calls `refresh_from_task` for `UP_FOR_RETRY` task 
instances, so a successor in state `None` keeps the old values. If the new 
version moves the task to a different `executor`, `queue` or `pool`, the 
restarted attempt runs the new code with the old routing.
   
   The non-running branch of `clear_task_instances` already handles this with 
`ti.refresh_from_task(task, dag_run=dr)`. Something like this would make the 
two paths match:
   
   ```python
   if self.task is not None:
       successor.refresh_from_task(self.task, dag_run=self.dag_run)
       successor.max_tries = self.try_number + self.task.retries
   ```
   



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