uranusjr commented on code in PR #66767:
URL: https://github.com/apache/airflow/pull/66767#discussion_r3489550468


##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -3530,12 +3530,22 @@ def _purge_task_instances_without_heartbeats(
             # Backfill dag_version_id for legacy tasks (Pydantic requires 
uuid.UUID).
             if not _ensure_ti_has_dag_version_id(ti, session, self.log):
                 continue
+            # ``_purge_task_instances_without_heartbeats`` doesn't load 
``ti.task``, so
+            # ``ti.is_eligible_to_retry()`` takes a fallback branch that 
misclassifies
+            # tasks declared with ``retries=0`` as retry-eligible. Decide 
directly from
+            # ``max_tries`` and ``try_number`` to match the "task loaded" 
branch instead.

Review Comment:
   `is_eligible_to_retry` has a branch handling a ti without task loaded 
https://github.com/apache/airflow/blob/899ce98b5c2730abeef19b15c840e537cd2b6227/airflow-core/src/airflow/models/taskinstance.py#L1936-L1950
   
   so I would implement it like this instead:
   
   ```python
   # Add a comment here explaining why ti.max_tries > 0 is checked.
   if ti.max_tries > 0 and ti.is_eligible_to_retry():
       task_callback_type = TaskInstanceState.UP_FOR_RETRY
   else:
       task_callback_type = TaskInstanceState.FAILED
   ```
   
   This makes it clearer we are just handling a case not covered by 
`is_eligible_to_retry`, instead of doing something entirely different.



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