You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by el...@apache.org on 2026/07/31 16:42:59 UTC

(superset) branch fix-report-frequency-croniter-bad-date created (now a452f7ae600)

This is an automated email from the ASF dual-hosted git repository.

eschutho pushed a change to branch fix-report-frequency-croniter-bad-date
in repository https://gitbox.apache.org/repos/asf/superset.git


      at a452f7ae600 fix(alerts-reports): catch CroniterBadDateError in report frequency validation

This branch includes the following new commits:

     new a452f7ae600 fix(alerts-reports): catch CroniterBadDateError in report frequency validation

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(superset) 01/01: fix(alerts-reports): catch CroniterBadDateError in report frequency validation

Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

eschutho pushed a commit to branch fix-report-frequency-croniter-bad-date
in repository https://gitbox.apache.org/repos/asf/superset.git

commit a452f7ae6000fadea34dad74540a9521494e112f
Author: Elizabeth Thompson <es...@gmail.com>
AuthorDate: Fri Jul 31 16:42:39 2026 +0000

    fix(alerts-reports): catch CroniterBadDateError in report frequency validation
    
    Fixes an uncaught CroniterBadDateError in report/alert frequency validation.
    
    marshmallow's validate_crontab only checks croniter.is_valid(), which is
    purely syntactic and accepts crontabs that never produce a real calendar
    date (e.g. "0 0 30 2 *" for February 30th). When ALERT_MINIMUM_INTERVAL or
    REPORT_MINIMUM_INTERVAL is configured >= 120s, validate_report_frequency
    iterates the schedule with croniter, which raises CroniterBadDateError
    instead of a ValidationError, propagating past the existing except
    ValidationError handling in CreateReportScheduleCommand and
    UpdateReportScheduleCommand and surfacing as an opaque 500.
---
 superset/commands/report/base.py              | 28 ++++++++++++++++-----------
 superset/commands/report/exceptions.py        | 17 ++++++++++++++++
 tests/unit_tests/commands/report/base_test.py | 27 +++++++++++++++++++++++++-
 3 files changed, 60 insertions(+), 12 deletions(-)

diff --git a/superset/commands/report/base.py b/superset/commands/report/base.py
index 353d9fea139..b69c36513c9 100644
--- a/superset/commands/report/base.py
+++ b/superset/commands/report/base.py
@@ -17,7 +17,7 @@
 import logging
 from typing import Any, Optional
 
-from croniter import croniter
+from croniter import croniter, CroniterBadDateError
 from flask import current_app as app
 from flask_babel import gettext as _
 from marshmallow import ValidationError
@@ -29,6 +29,7 @@ from superset.commands.report.exceptions import (
     ChartNotSavedValidationError,
     DashboardNotFoundValidationError,
     DashboardNotSavedValidationError,
+    ReportScheduleCrontabNotValidError,
     ReportScheduleEitherChartOrDashboardError,
     ReportScheduleForbiddenError,
     ReportScheduleFrequencyNotAllowed,
@@ -288,13 +289,18 @@ class BaseReportScheduleCommand(BaseCommand):
             return
 
         iterations = 60 if minimum_interval <= 3660 else 24
-        schedule = croniter(cron_schedule)
-        current_exec = next(schedule)
-
-        for _i in range(iterations):
-            next_exec = next(schedule)
-            diff, current_exec = next_exec - current_exec, next_exec
-            if int(diff) < minimum_interval:
-                raise ReportScheduleFrequencyNotAllowed(
-                    report_type=report_type, minimum_interval=minimum_interval
-                )
+        try:
+            schedule = croniter(cron_schedule)
+            current_exec = next(schedule)
+
+            for _i in range(iterations):
+                next_exec = next(schedule)
+                diff, current_exec = next_exec - current_exec, next_exec
+                if int(diff) < minimum_interval:
+                    raise ReportScheduleFrequencyNotAllowed(
+                        report_type=report_type, minimum_interval=minimum_interval
+                    )
+        except CroniterBadDateError as ex:
+            raise ReportScheduleCrontabNotValidError(
+                cron_schedule=cron_schedule
+            ) from ex
diff --git a/superset/commands/report/exceptions.py b/superset/commands/report/exceptions.py
index a2370196eb1..a248d494e0f 100644
--- a/superset/commands/report/exceptions.py
+++ b/superset/commands/report/exceptions.py
@@ -133,6 +133,23 @@ class ReportScheduleFrequencyNotAllowed(ValidationError):  # noqa: N818
         )
 
 
+class ReportScheduleCrontabNotValidError(ValidationError):  # noqa: N818
+    """
+    Marshmallow validation error for a crontab that is syntactically valid
+    but never matches a real calendar date (e.g. February 30th)
+    """
+
+    def __init__(self, cron_schedule: str = "") -> None:
+        super().__init__(
+            _(
+                "Invalid crontab schedule: %(cron_schedule)s never matches"
+                " a valid date",
+                cron_schedule=cron_schedule,
+            ),
+            field_name="crontab",
+        )
+
+
 class ChartNotSavedValidationError(ValidationError):
     """
     Marshmallow validation error for charts that haven't been saved yet
diff --git a/tests/unit_tests/commands/report/base_test.py b/tests/unit_tests/commands/report/base_test.py
index ec8c6973406..93055e38a32 100644
--- a/tests/unit_tests/commands/report/base_test.py
+++ b/tests/unit_tests/commands/report/base_test.py
@@ -26,7 +26,10 @@ from unittest.mock import patch
 import pytest
 
 from superset.commands.report.base import BaseReportScheduleCommand
-from superset.commands.report.exceptions import ReportScheduleFrequencyNotAllowed
+from superset.commands.report.exceptions import (
+    ReportScheduleCrontabNotValidError,
+    ReportScheduleFrequencyNotAllowed,
+)
 from superset.reports.models import ReportScheduleType
 
 REPORT_TYPES = {
@@ -174,6 +177,28 @@ def test_validate_report_frequency_report_only(schedule: str) -> None:
     )
 
 
+@pytest.mark.parametrize("report_type", REPORT_TYPES)
+@app_custom_config(
+    alert_minimum_interval=int(timedelta(minutes=5).total_seconds()),
+    report_minimum_interval=int(timedelta(minutes=5).total_seconds()),
+)
+def test_validate_report_frequency_never_matching_crontab(report_type: str) -> None:
+    """
+    Test the ``validate_report_frequency`` method with a crontab that is
+    syntactically valid but never matches a real calendar date (Feb 30th).
+
+    Such schedules pass ``croniter.is_valid()`` (purely syntactic) and thus
+    marshmallow schema validation, but raise ``CroniterBadDateError`` when
+    iterated. This should surface as a ``ValidationError`` rather than
+    propagating the raw croniter exception.
+    """
+    with pytest.raises(ReportScheduleCrontabNotValidError):
+        BaseReportScheduleCommand().validate_report_frequency(
+            "0 0 30 2 *",
+            report_type,
+        )
+
+
 @pytest.mark.parametrize("report_type", REPORT_TYPES)
 @pytest.mark.parametrize("schedule", TEST_SCHEDULES)
 @app_custom_config(