From e60f42187bffc85df65838433eda27447c8d1af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Beltr=C3=A1n=20Mora?= <94113100+dbeltrankyl@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:01:27 +0100 Subject: [PATCH] Fix issue with the is_wrapper attribute (#2033) * Fix issue with the wrapper attribute * Fix issue with the wrapper attribute --- autosubmit/job/job.py | 14 ++++++++++++++ test/unit/test_job_pytest.py | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/autosubmit/job/job.py b/autosubmit/job/job.py index 072d7a68..732dca29 100644 --- a/autosubmit/job/job.py +++ b/autosubmit/job/job.py @@ -261,6 +261,19 @@ def __init__(self, name, job_id, status, priority): self.wrapper_name = None self.is_wrapper = False + def _adjust_new_parameters(self) -> None: + """ + Adjusts job parameters for compatibility with newer added attributes. + """ + # This function is always called at the start of a new run ( from update_parameters ) + if not hasattr(self, 'is_wrapper'): # Added in 4.1.12 + if not self.packed: + self.is_wrapper = False + self.wrapper_name = self.name + else: + self.is_wrapper = True + self.wrapper_name = "wrapped" + def _init_runtime_parameters(self): # hetjobs self.het = {'HETSIZE': 0} @@ -2030,6 +2043,7 @@ def update_parameters(self, as_conf, parameters, :type parameters: dict """ as_conf.reload() + self._adjust_new_parameters() self._init_runtime_parameters() if hasattr(self, "start_time"): self.start_time = time.time() diff --git a/test/unit/test_job_pytest.py b/test/unit/test_job_pytest.py index 60b871f5..a97607ac 100644 --- a/test/unit/test_job_pytest.py +++ b/test/unit/test_job_pytest.py @@ -162,3 +162,19 @@ def test_update_parameters_attributes( assert hasattr(job, attr) assert getattr(job, attr) == attributes_to_check[attr] if type( attributes_to_check[attr]) is not list else attributes_to_check[attr][0] + +@pytest.mark.parametrize('test_packed', [ + False, + True, +], ids=["Simple job", "Wrapped job"]) +def test_adjust_new_parameters(test_packed): + job = Job('dummy', '1', 0, 1) + del job.is_wrapper + del job.wrapper_name + job.packed = test_packed + job._adjust_new_parameters() + assert job.is_wrapper == test_packed + if test_packed: + assert job.wrapper_name == "wrapped" + else: + assert job.wrapper_name == "dummy"