diff --git a/backend/app/api/schedules.py b/backend/app/api/schedules.py index 74273857..728cac71 100644 --- a/backend/app/api/schedules.py +++ b/backend/app/api/schedules.py @@ -494,7 +494,7 @@ async def list_fires(schedule_id: str, limit: str | None = None, before: str | N await _get(session, schedule_id) size = 20 if limit is not None: - if not limit.strip().isdigit() or not 1 <= int(limit) <= 100: + if not limit.strip().isdecimal() or not 1 <= int(limit) <= 100: raise _invalid(f"每页条数需要是 1 到 100 之间的整数,当前为「{limit}」", "limit") size = int(limit) stmt = select(ScheduleFire).where(ScheduleFire.schedule_id == schedule_id) diff --git a/backend/app/scheduler/cron.py b/backend/app/scheduler/cron.py index c944b671..13711ae1 100644 --- a/backend/app/scheduler/cron.py +++ b/backend/app/scheduler/cron.py @@ -128,7 +128,8 @@ def _parse_item(item: str, key: str, label: str, low: int, high: int) -> set[int base, slash, step_text = item.partition("/") step = 1 if slash: - if not step_text.isdigit() or int(step_text) == 0: + # isdecimal 而不是 isdigit:「²」算 digit,int() 却认不得它 + if not step_text.isdecimal() or int(step_text) == 0: raise CronError(f"「{label}」字段「{item}」的步长需要是正整数,现在是「{step_text}」", key) step = int(step_text) if base == "*": @@ -150,7 +151,7 @@ def _parse_item(item: str, key: str, label: str, low: int, high: int) -> set[int def _value(token: str, item: str, key: str, label: str, low: int, high: int, *, range_end: bool = False) -> int: word = token.strip().upper() - if word.isdigit(): + if word.isdecimal(): number = int(word) if not low <= number <= high: raise CronError(f"「{label}」字段的 {number} 超出范围,允许 {_ALLOWED[key]}", key) diff --git a/backend/app/scheduler/service.py b/backend/app/scheduler/service.py index 76562115..932c439a 100644 --- a/backend/app/scheduler/service.py +++ b/backend/app/scheduler/service.py @@ -240,7 +240,8 @@ async def fire_once(schedule_id: str, fire_at: datetime, kind: str, *, actor: st try: inputs = render_inputs(check_template(template), template_values(fire_at, tz, cron_expr)) except (TemplateError, cron.CronError, cron.TimezoneError) as e: - return await _record(schedule_id, fire_at, kind, "failed_to_start", f"输入模板无法渲染:{e}", {}) + # 存进库之后才坏掉的(手改过库、时区库升级删了时区):照实说是哪一项,不发起 + return await _record(schedule_id, fire_at, kind, "failed_to_start", f"无法生成这次运行的输入:{e}", {}) busy = await _active_run(schedule_id) if busy is not None: reason = f"上一次运行({busy[:8]})还没有结束,按设置跳过这次触发" diff --git a/backend/tests/test_scheduler_cron.py b/backend/tests/test_scheduler_cron.py index 005f9e60..90b76d72 100644 --- a/backend/tests/test_scheduler_cron.py +++ b/backend/tests/test_scheduler_cron.py @@ -84,6 +84,8 @@ def test_expression_is_normalized(): ("0 9 * * L", ["「周」", "L"]), ("0 9 1,,2 * *", ["「日」"]), ("@daily", ["5 个字段"]), + ("² * * * *", ["「分」", "²"]), + ("*/² * * * *", ["「分」", "步长"]), ]) def test_invalid_expressions_explain_in_chinese(expr, fragments): with pytest.raises(cron.CronError) as caught: diff --git a/backend/tests/test_schedules_api.py b/backend/tests/test_schedules_api.py index a4e36688..cc44788c 100644 --- a/backend/tests/test_schedules_api.py +++ b/backend/tests/test_schedules_api.py @@ -436,6 +436,8 @@ async def test_fire_history_pages_and_last_fire(client): assert last["reason"] == "第 4 次" and set(last) == FIRE_KEYS bad = await client.get(f"/api/schedules/{sid}/fires", params={"limit": "many"}) assert bad.status_code == 422 and bad.json()["field"] == "limit" + bad = await client.get(f"/api/schedules/{sid}/fires", params={"limit": "²"}) + assert bad.status_code == 422 and bad.json()["field"] == "limit" bad = await client.get(f"/api/schedules/{sid}/fires", params={"before": "昨天"}) assert bad.status_code == 422 and bad.json()["field"] == "before"