You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by je...@apache.org on 2022/02/17 21:38:58 UTC
[airflow] 07/43: Do not set `TaskInstance.max_tries` in `refresh_from_task` (#21018)
This is an automated email from the ASF dual-hosted git repository.
jedcunningham pushed a commit to branch v2-2-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 07102e96dfb3c9794882f562548b37738ee4a37a
Author: yuqian90 <yu...@gmail.com>
AuthorDate: Thu Jan 27 06:47:10 2022 +0800
Do not set `TaskInstance.max_tries` in `refresh_from_task` (#21018)
(cherry picked from commit e3832a77a3e0d374dfdbe14f34a941d22c9c459d)
---
airflow/models/taskinstance.py | 4 +++-
tests/models/test_taskinstance.py | 6 ++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/airflow/models/taskinstance.py b/airflow/models/taskinstance.py
index 281d067..ec34156 100644
--- a/airflow/models/taskinstance.py
+++ b/airflow/models/taskinstance.py
@@ -447,6 +447,7 @@ class TaskInstance(Base, LoggingMixin):
self.run_id = run_id
self.try_number = 0
+ self.max_tries = self.task.retries
self.unixname = getuser()
if state:
self.state = state
@@ -775,7 +776,8 @@ class TaskInstance(Base, LoggingMixin):
self.pool_slots = task.pool_slots
self.priority_weight = task.priority_weight_total
self.run_as_user = task.run_as_user
- self.max_tries = task.retries
+ # Do not set max_tries to task.retries here because max_tries is a cumulative
+ # value that needs to be stored in the db.
self.executor_config = task.executor_config
self.operator = task.task_type
diff --git a/tests/models/test_taskinstance.py b/tests/models/test_taskinstance.py
index d111371..4fec49f 100644
--- a/tests/models/test_taskinstance.py
+++ b/tests/models/test_taskinstance.py
@@ -2143,6 +2143,12 @@ def test_refresh_from_task(pool_override):
assert ti.executor_config == task.executor_config
assert ti.operator == DummyOperator.__name__
+ # Test that refresh_from_task does not reset ti.max_tries
+ expected_max_tries = task.retries + 10
+ ti.max_tries = expected_max_tries
+ ti.refresh_from_task(task)
+ assert ti.max_tries == expected_max_tries
+
class TestRunRawTaskQueriesCount:
"""