From 20f506e660ac11d9af62ca3c6d61c35320fc448f Mon Sep 17 00:00:00 2001 From: juanmicl <19253629+juanmicl@users.noreply.github.com> Date: Sun, 30 Aug 2026 22:44:09 +0200 Subject: [PATCH 1/3] fix: skip schedules with invalid cron_offset instead of crashing the scheduler --- taskiq/cli/scheduler/run.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/taskiq/cli/scheduler/run.py b/taskiq/cli/scheduler/run.py index 06382c43..574b265d 100644 --- a/taskiq/cli/scheduler/run.py +++ b/taskiq/cli/scheduler/run.py @@ -99,7 +99,10 @@ def is_cron_task_now( # If timezone was specified as string we convert it timezone # offset and then apply. elif offset and isinstance(offset, str): - now = now.astimezone(ZoneInfo(offset)) + try: + now = now.astimezone(ZoneInfo(offset)) + except Exception as e: + raise CronValueError(e) from e try: return pycron.is_now(cron_value, now) From d5fe06db95eba2436d8c7a9d6431614d41887253 Mon Sep 17 00:00:00 2001 From: juanmicl <19253629+juanmicl@users.noreply.github.com> Date: Tue, 1 Sep 2026 22:53:14 +0200 Subject: [PATCH 2/3] test: add regression tests for invalid cron_offset handling --- tests/cli/scheduler/test_is_cron_task_now.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/cli/scheduler/test_is_cron_task_now.py b/tests/cli/scheduler/test_is_cron_task_now.py index bbbe079b..630da454 100644 --- a/tests/cli/scheduler/test_is_cron_task_now.py +++ b/tests/cli/scheduler/test_is_cron_task_now.py @@ -75,3 +75,21 @@ def test_is_cron_task_now( def test_is_cron_task_now_invalid_cron() -> None: with pytest.raises(CronValueError): is_cron_task_now("invalid cron", datetime.now()) + + +def test_is_cron_task_now_invalid_offset_string() -> None: + with pytest.raises(CronValueError): + is_cron_task_now( + cron_value="* * * * *", + now=datetime.now(timezone.utc), + offset="UTC+3", + ) + + +def test_is_cron_task_now_unknown_timezone_name() -> None: + with pytest.raises(CronValueError): + is_cron_task_now( + cron_value="* * * * *", + now=datetime.now(timezone.utc), + offset="Europa/Madrid", + ) From ec1abbd82a6f895852afacf3c36f8a4070468c6d Mon Sep 17 00:00:00 2001 From: juanmicl <19253629+juanmicl@users.noreply.github.com> Date: Wed, 16 Sep 2026 12:44:22 +0200 Subject: [PATCH 3/3] fix: catch ZoneInfoNotFoundError and ModuleNotFoundError for cron_offset --- taskiq/cli/scheduler/run.py | 7 +++++-- tests/cli/scheduler/test_is_cron_task_now.py | 17 ++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/taskiq/cli/scheduler/run.py b/taskiq/cli/scheduler/run.py index 574b265d..744ca0f4 100644 --- a/taskiq/cli/scheduler/run.py +++ b/taskiq/cli/scheduler/run.py @@ -4,7 +4,7 @@ from datetime import datetime, timedelta, timezone from logging import basicConfig, getLogger from typing import Any, TypeAlias -from zoneinfo import ZoneInfo +from zoneinfo import ZoneInfo, ZoneInfoNotFoundError import pycron @@ -101,7 +101,10 @@ def is_cron_task_now( elif offset and isinstance(offset, str): try: now = now.astimezone(ZoneInfo(offset)) - except Exception as e: + # ZoneInfoNotFoundError for unknown keys, ModuleNotFoundError + # for systems without timezone data available (e.g. missing + # tzdata on Windows). + except (ZoneInfoNotFoundError, ModuleNotFoundError) as e: raise CronValueError(e) from e try: diff --git a/tests/cli/scheduler/test_is_cron_task_now.py b/tests/cli/scheduler/test_is_cron_task_now.py index 630da454..36b1365a 100644 --- a/tests/cli/scheduler/test_is_cron_task_now.py +++ b/tests/cli/scheduler/test_is_cron_task_now.py @@ -77,19 +77,14 @@ def test_is_cron_task_now_invalid_cron() -> None: is_cron_task_now("invalid cron", datetime.now()) -def test_is_cron_task_now_invalid_offset_string() -> None: - with pytest.raises(CronValueError): - is_cron_task_now( - cron_value="* * * * *", - now=datetime.now(timezone.utc), - offset="UTC+3", - ) - - -def test_is_cron_task_now_unknown_timezone_name() -> None: +@pytest.mark.parametrize( + "offset", + ["UTC+3", "Europa/Madrid"], +) +def test_is_cron_task_now_invalid_offset_string(offset: str) -> None: with pytest.raises(CronValueError): is_cron_task_now( cron_value="* * * * *", now=datetime.now(timezone.utc), - offset="Europa/Madrid", + offset=offset, )