From cf7f6b0fe72a888d48c07de13289faa3da87bab9 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/2] 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 03c9faf6..c7ee03f1 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 5fa2c055e66a2badf49d9604870e4762bc06de51 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/2] 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", + )