From 685824692ee7d078241d05eab6da0acac64aef9e Mon Sep 17 00:00:00 2001 From: Kevin Kaspari Date: Fri, 17 Jan 2025 08:47:35 -0800 Subject: [PATCH] Use localize instead of replace when writing tz info --- tron/core/jobrun.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tron/core/jobrun.py b/tron/core/jobrun.py index db76b64a3..460b8b20a 100644 --- a/tron/core/jobrun.py +++ b/tron/core/jobrun.py @@ -111,13 +111,15 @@ def to_json(state_data: dict) -> Optional[str]: @staticmethod def from_json(state_data: str): - """Deserialize the JobRun instance to a JSON string.""" + """Deserialize the JobRun instance from a JSON string.""" try: json_data = json.loads(state_data) - if json_data["run_time"]: - run_time = datetime.datetime.fromisoformat(json_data["run_time"]) + run_time_str = json_data["run_time"] + if run_time_str: + run_time = datetime.datetime.fromisoformat(run_time_str) if json_data["time_zone"]: - run_time = run_time.replace(tzinfo=pytz.timezone(json_data["time_zone"])) + tz = pytz.timezone(json_data["time_zone"]) + run_time = tz.localize(run_time) else: run_time = None deserialized_data = {