Skip to content

fix(calendar): localize cron start_time to timetable timezone before computing planned runs - #71248

Open
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix/calendar-cron-timezone
Open

fix(calendar): localize cron start_time to timetable timezone before computing planned runs#71248
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix/calendar-cron-timezone

Conversation

@waterWang

Copy link
Copy Markdown

Closes #71234

Problem

Calendar view's planned/future runs for cron-based timetables are computed
in UTC wall-clock instead of the DAG's configured timezone. When a DAG
uses a non-UTC default_timezone (e.g. Asia/Seoul, UTC+9) with a cron
schedule like "0 8 * * *", the planned runs appear at 17:00 instead of
08:00 — exactly a UTC-vs-local offset.

The root cause is in CalendarService._calculate_cron_planned_runs():
croniter receives last_data_interval.end (a UTC-aware datetime) as
start_time and reads its timezone — UTC — so the cron expression is
matched against UTC wall-clock. The real scheduler (CronMixin._get_next)
correctly localizes the start time to the timetable's own timezone before
calling croniter.

Fix

  1. Add imports for convert_to_utc, make_aware, make_naive from
    airflow._shared.timezones.timezone (same utilities used by
    CronMixin._get_next).

  2. In _calculate_cron_planned_runs:

    • Extract the timetable's _timezone from the CronMixin cast.
    • Localize start_time to that timezone via make_naive() before
      constructing croniter.
    • Convert each result back to UTC via convert_to_utc(make_aware(...)).

This matches the exact pattern used by CronMixin._get_next() in
airflow/timetables/_cron.py.

Testing

All 19 existing calendar tests continue to pass. The fix was verified
locally by the issue reporter with an additional regression test for a
non-UTC cron timetable (20/20 passing).

Related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calendar view computes planned runs for cron timetables in UTC, ignoring the DAG's configured timezone

1 participant