Skip to content

Fix Calendar view computing cron planned runs in UTC instead of the Dag's timezone - #71243

Open
simon-hoon wants to merge 2 commits into
apache:mainfrom
simon-hoon:fix-calendar-cron-timezone
Open

Fix Calendar view computing cron planned runs in UTC instead of the Dag's timezone#71243
simon-hoon wants to merge 2 commits into
apache:mainfrom
simon-hoon:fix-calendar-cron-timezone

Conversation

@simon-hoon

@simon-hoon simon-hoon commented Aug 6, 2026

Copy link
Copy Markdown

closes: #71234

CalendarService._calculate_cron_planned_runs() handed croniter a UTC-tagged start_time when computing "planned" (future, not-yet-executed) calendar cells for cron-based timetables. croniter matches cron fields against whatever wall-clock its start_time carries, so for a Dag on a non-UTC default_timezone, planned runs came out shifted by the UTC offset (e.g. a 08:00 Asia/Seoul schedule showed planned cells at 17:00).

This localizes start_time into the timetable's own timezone before constructing croniter, converting results back to UTC — same math as the common branch of CronMixin._get_next. Its _covers_every_hour DST fold-hour workaround is intentionally not replicated, so every-hour crons in a DST timezone can undercount the folded hour's cell by one run, once a year. Historical (already-executed) runs were unaffected, since those come straight from already-correct DagRun rows.

Added a regression test for a non-UTC cron timetable in test_calendar.py.

Verified with uv sync --package apache-airflow-core + pytest on test_calendar.py: 20/20 passing (19 existing + 1 new).

Before/after (local demo, schedule="0 8 * * *", AIRFLOW__CORE__DEFAULT_TIMEZONE=Asia/Seoul): planned cells moved from the 16:00–17:00 row to the 08:00 row, now matching the Success row above.
image
image


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code

Generated-by: Claude Code following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

CalendarService._calculate_cron_planned_runs() handed croniter a
UTC-tagged start_time, so cron fields were matched against UTC
wall-clock instead of the timetable's configured timezone. Localize
start_time first, like CronMixin._get_next does, and convert results
back to UTC.

Closes apache#71234
@boring-cyborg

boring-cyborg Bot commented Aug 6, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

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