From fa406db74d2dd8d88ca4b9451d0da1f9be3c7c7b Mon Sep 17 00:00:00 2001 From: Guido Petretto Date: Fri, 8 Nov 2024 11:51:12 +0100 Subject: [PATCH] fix python 3.9 compatibility --- src/jobflow_remote/jobs/jobcontroller.py | 10 ++++++++-- tests/db/utils/test_data.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/jobflow_remote/jobs/jobcontroller.py b/src/jobflow_remote/jobs/jobcontroller.py index 92625d15..9e6dc508 100644 --- a/src/jobflow_remote/jobs/jobcontroller.py +++ b/src/jobflow_remote/jobs/jobcontroller.py @@ -3881,8 +3881,14 @@ def lock_job_for_update( no_retry = True except RemoteError as e: error = f"Remote error: {e.msg}" - if e.__cause__: - trace = traceback.format_exception(e.__cause__) + cause = e.__cause__ + if cause: + # this is required for support of python 3.9. In 3.10 the API + # changed and format_exception(e) could be used instead. + # Do that if/when support for 3.9 is dropped. + trace = traceback.format_exception( + type(cause), cause, cause.__traceback__ + ) error += "\ncaused by:\n" + "".join(trace) no_retry = e.no_retry except Exception: diff --git a/tests/db/utils/test_data.py b/tests/db/utils/test_data.py index 75be80ae..f174be63 100644 --- a/tests/db/utils/test_data.py +++ b/tests/db/utils/test_data.py @@ -55,7 +55,7 @@ def test_get_past_time_rounded(): def test_get_utc_offset(): from jobflow_remote.utils.data import get_utc_offset - assert get_utc_offset("America/Los_Angeles") == "-07:00" + assert get_utc_offset("America/Buenos_Aires") == "-03:00" assert get_utc_offset("Europe/Moscow") == "+03:00" assert get_utc_offset("UTC") == "+00:00" assert get_utc_offset("Asia/Shanghai") == "+08:00"