Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ContinuousTimetable false triggering when last run ends in future #45175

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions airflow/timetables/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,21 @@ def next_dagrun_info(
) -> DagRunInfo | None:
if restriction.earliest is None: # No start date, won't run.
return None

current_time = timezone.coerce_datetime(timezone.utcnow())

if last_automated_data_interval is not None: # has already run once
start = last_automated_data_interval.end
end = timezone.coerce_datetime(timezone.utcnow())
if last_automated_data_interval.end > current_time: # start date is future
start = restriction.earliest
elapsed = last_automated_data_interval.end - last_automated_data_interval.start

end = start + elapsed.as_timedelta()
else:
start = last_automated_data_interval.end
end = current_time
else: # first run
start = restriction.earliest
end = max(
restriction.earliest, timezone.coerce_datetime(timezone.utcnow())
) # won't run any earlier than start_date
end = max(restriction.earliest, current_time)

if restriction.latest is not None and end > restriction.latest:
return None
Expand Down
11 changes: 11 additions & 0 deletions tests/timetables/test_continuous_timetable.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,14 @@ def test_no_runs_after_end_date(timetable, restriction):
)

assert next_info is None


@time_machine.travel(BEFORE_DATE)
def test_no_false_triggering_with_future_start_date_after_run(timetable, restriction):
next_info = timetable.next_dagrun_info(
last_automated_data_interval=DataInterval(BEFORE_DATE, BEFORE_DATE.add(hours=1)),
restriction=restriction,
)

assert next_info is not None
assert next_info.data_interval.start == START_DATE