Skip to content

Commit

Permalink
Remove legacy hack for TaskInstance without DagRun (#20108)
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored Dec 8, 2021
1 parent 7fb301b commit b0eecc3
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions airflow/models/taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,23 +890,6 @@ def get_previous_dagrun(
return None

dr = self.get_dagrun(session=session)

# LEGACY: most likely running from unit tests
if not dr:
# Means that this TaskInstance is NOT being run from a DR, but from a catchup
try:
# XXX: This uses DAG internals, but as the outer comment
# said, the block is only reached for legacy reasons for
# development code, so that's OK-ish.
schedule = dag.timetable._schedule # type: ignore
except AttributeError:
return None
dt = pendulum.instance(self.execution_date)
return TaskInstance(
task=self.task,
execution_date=schedule.get_prev(dt),
)

dr.dag = dag

# We always ignore schedule in dagrun lookup when `state` is given
Expand Down Expand Up @@ -1121,7 +1104,7 @@ def ready_for_retry(self):
return self.state == State.UP_FOR_RETRY and self.next_retry_datetime() < timezone.utcnow()

@provide_session
def get_dagrun(self, session: Session = NEW_SESSION):
def get_dagrun(self, session: Session = NEW_SESSION) -> "DagRun":
"""
Returns the DagRun for this TaskInstance
Expand Down

0 comments on commit b0eecc3

Please sign in to comment.