From 9f21c32f9a3891995373c07c5644068d22ce18e5 Mon Sep 17 00:00:00 2001 From: Sam Wheating Date: Wed, 31 Jan 2024 06:47:35 -0800 Subject: [PATCH] Displaying "actual" try number in TaskInstance view (#34635) (cherry picked from commit ce6ac4176445efbd6097cdcdb10782752a4f1bf9) --- airflow/models/taskinstance.py | 12 ++++++++++++ airflow/www/views.py | 6 ++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/airflow/models/taskinstance.py b/airflow/models/taskinstance.py index b653964580c55..cbbc2b726c42d 100644 --- a/airflow/models/taskinstance.py +++ b/airflow/models/taskinstance.py @@ -1421,6 +1421,18 @@ def try_number(self): """ return _get_try_number(task_instance=self) + @try_number.expression + def try_number(cls): + """ + This is what will be used by SQLAlchemy when filtering on try_number. + + This is required because the override in the get_try_number function causes + try_number values to be off by one when listing tasks in the UI. + + :meta private: + """ + return cls._try_number + @try_number.setter def try_number(self, value: int) -> None: """ diff --git a/airflow/www/views.py b/airflow/www/views.py index 4bf06d35c732a..5252d20ce3f4d 100644 --- a/airflow/www/views.py +++ b/airflow/www/views.py @@ -5483,7 +5483,7 @@ class TaskInstanceModelView(AirflowModelView): "priority_weight", "queue", "queued_dttm", - "try_number", + "prev_attempted_tries", "pool", "queued_by_job_id", "external_executor_id", @@ -5512,9 +5512,7 @@ class TaskInstanceModelView(AirflowModelView): "queued_by_job_id", ] - label_columns = { - "dag_run.execution_date": "Logical Date", - } + label_columns = {"dag_run.execution_date": "Logical Date", "prev_attempted_tries": "Try Number"} search_columns = [ "state",