From e5208ef6db8212a082a7141d19dd3d215bc68299 Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Sun, 1 Mar 2026 16:35:34 +0100 Subject: [PATCH] feat: Handle missing or invalid period_start in Heuristic from_json (@monperrus at work) When deserializing a Heuristic from JSON, if `period_start` is missing or invalid, default it to `datetime.min`. This ensures that heuristics with incomplete or malformed start dates are treated as active from the earliest possible point. --- heuristic.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/heuristic.py b/heuristic.py index d552111..08e1eaf 100644 --- a/heuristic.py +++ b/heuristic.py @@ -148,7 +148,10 @@ def from_json(obj: Any) -> Heuristic: files = tuple(obj["files"]) branch_name_prefix = tuple(obj["branch_name_prefix"]) commit_message_prefix = tuple(obj["commit_message_prefix"]) - period_start = datetime.now() # datetime.fromisoformat(obj["period_start"]) + try: + period_start = datetime.fromisoformat(obj["period_start"]) + except (ValueError, KeyError): + period_start = datetime.min # treat missing/empty as "active from the beginning" period_end = None if not (obj["period_end"] is None or obj["period_end"] in ["None", "null"]): period_end = datetime.fromisoformat(obj["period_end"])