This is an automated email from the ASF dual-hosted git repository.
eschutho pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 4a4f0685fd6 fix(reports): prevent bad-date crontab from crashing the
report scheduler for all tenants (#42486)
4a4f0685fd6 is described below
commit 4a4f0685fd671d592c4e03891ba1ba4c4250542b
Author: Elizabeth Thompson <[email protected]>
AuthorDate: Tue Jul 28 15:02:36 2026 -0700
fix(reports): prevent bad-date crontab from crashing the report scheduler
for all tenants (#42486)
---
superset/tasks/cron_util.py | 19 +++++++++++++------
tests/unit_tests/tasks/test_cron_util.py | 21 +++++++++++++++++++++
2 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/superset/tasks/cron_util.py b/superset/tasks/cron_util.py
index 53fba16e12f..904371d5883 100644
--- a/superset/tasks/cron_util.py
+++ b/superset/tasks/cron_util.py
@@ -19,7 +19,7 @@ import logging
from collections.abc import Iterator
from datetime import datetime, timedelta
-from croniter import croniter
+from croniter import croniter, CroniterBadDateError
from flask import current_app
from pytz import timezone as pytz_timezone, UnknownTimeZoneError
@@ -42,8 +42,15 @@ def cron_schedule_window(
start_at = time_now - timedelta(seconds=window_size / 2)
stop_at = time_now + timedelta(seconds=window_size / 2)
crons = croniter(cron, start_at)
- for schedule in crons.all_next(datetime):
- if schedule >= stop_at:
- break
- # convert schedule back to utc
- yield schedule.astimezone(utc).replace(tzinfo=None)
+ try:
+ for schedule in crons.all_next(datetime):
+ if schedule >= stop_at:
+ break
+ # convert schedule back to utc
+ yield schedule.astimezone(utc).replace(tzinfo=None)
+ except CroniterBadDateError:
+ logger.error(
+ "Cron schedule %s can never match a valid date; "
+ "it will not produce any executions",
+ cron,
+ )
diff --git a/tests/unit_tests/tasks/test_cron_util.py
b/tests/unit_tests/tasks/test_cron_util.py
index 128e4141c31..03a608a978e 100644
--- a/tests/unit_tests/tasks/test_cron_util.py
+++ b/tests/unit_tests/tasks/test_cron_util.py
@@ -235,3 +235,24 @@ def test_cron_schedule_window_chicago_daylight(
assert (
list(cron.strftime("%A, %d %B %Y, %H:%M:%S") for cron in datetimes) ==
expected # noqa: C400
)
+
+
[email protected](
+ "current_dttm, cron, expected",
+ [
+ ("2020-01-01T08:59:01+00:00", "0 0 30 2 *", []),
+ ("2020-01-01T08:59:01+00:00", "0 0 31 4 *", []),
+ ],
+)
+def test_cron_schedule_window_invalid_cron_date(
+ current_dttm: str, cron: str, expected: list[FakeDatetime]
+) -> None:
+ """
+ Reports scheduler: Test cron schedule window for a cron that is
+ syntactically valid but can never match a real calendar date
+ """
+
+ datetimes = cron_schedule_window(datetime.fromisoformat(current_dttm),
cron, "UTC")
+ assert (
+ list(cron.strftime("%A, %d %B %Y, %H:%M:%S") for cron in datetimes) ==
expected # noqa: C400
+ )