fix(api): align cron validator with celery parser

This commit is contained in:
Víctor Fernández Poyatos
2026-02-17 12:03:59 +01:00
parent 4d44140ab1
commit e1ba7bce57
2 changed files with 14 additions and 0 deletions
@@ -26,6 +26,7 @@ class TestCron5FieldsValidator:
"0 2 0 * *",
"0 2 * 13 *",
"* * * * 7",
"5/15 * * * *",
"0 2 * * 9",
"*/0 * * * *",
"",
+13
View File
@@ -1,6 +1,7 @@
import re
import string
from celery.schedules import crontab
from django.core.exceptions import ValidationError
from django.utils.translation import gettext as _
@@ -175,3 +176,15 @@ def cron_5_fields_validator(value: str) -> None:
field_ranges = ((0, 59), (0, 23), (1, 31), (1, 12), (0, 6))
for part, (min_value, max_value) in zip(parts, field_ranges, strict=False):
_validate_cron_field(part, min_value, max_value)
# Keep model-level validation aligned with Celery crontab parsing.
try:
crontab(
minute=parts[0],
hour=parts[1],
day_of_month=parts[2],
month_of_year=parts[3],
day_of_week=parts[4],
)
except ValueError as exc:
raise ValidationError("Invalid cron expression.") from exc