Skip to content

Commit

Permalink
Use original task's start_date if a task continues after deferral (…
Browse files Browse the repository at this point in the history
…#20062)

GitOrigin-RevId: 5cc5f434d745452651bca76ba6d2406167b7e2b9
  • Loading branch information
eskarimov authored and Cloud Composer Team committed Oct 4, 2022
1 parent 63f7819 commit 8f4a0c5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion airflow/models/taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,8 @@ def check_and_change_state_before_execution(
# Attempt 0 for the first attempt).
# Set the task start date. In case it was re-scheduled use the initial
# start date that is recorded in task_reschedule table
self.start_date = timezone.utcnow()
# If the task continues after being deferred (next_method is set), use the original start_date
self.start_date = self.start_date if self.next_method else timezone.utcnow()
if self.state == State.UP_FOR_RESCHEDULE:
task_reschedule: TR = TR.query_for_task_instance(self, session=session).first()
if task_reschedule:
Expand Down Expand Up @@ -1533,6 +1534,8 @@ def _defer_task(self, session, defer: TaskDeferred):
session.flush()

# Then, update ourselves so it matches the deferral request
# Keep an eye on the logic in `check_and_change_state_before_execution()`
# depending on self.next_method semantics
self.state = State.DEFERRED
self.trigger_id = trigger_row.id
self.next_method = defer.method_name
Expand Down

0 comments on commit 8f4a0c5

Please sign in to comment.