From cec5cb8157b9082abc8e18d922a8335b9b2848ae Mon Sep 17 00:00:00 2001 From: Nathan Freeman Date: Wed, 18 Oct 2023 15:57:05 -0500 Subject: [PATCH] bugfix: use correct accessors for template object --- .../core/workflows/executors/WorkflowExecutor.py | 6 +++--- src/engine/src/helpers/TemplateMapper.py | 15 ++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/engine/src/core/workflows/executors/WorkflowExecutor.py b/src/engine/src/core/workflows/executors/WorkflowExecutor.py index 59492f39..5dedb594 100644 --- a/src/engine/src/core/workflows/executors/WorkflowExecutor.py +++ b/src/engine/src/core/workflows/executors/WorkflowExecutor.py @@ -490,9 +490,9 @@ def _prepare_pipeline_fs(self): # The log file for this pipeline run self.state.ctx.pipeline.log_file = f"{self.state.ctx.pipeline.work_dir}logs.txt" - # Set the work_dir on the WorkflowExecutor as well. Will be used for - # cleaning up all the temporary files/dirs after the state is reset. - # (Which means that ther will be no self.state.ctx.pipeline.work_dir) + # Set the work_dir on the WorkflowExecutor as well. + # NOTE Will be used for cleaning up all the temporary files/dirs after + # the state is reset. (Which means that ther will be no self.state.ctx.pipeline.work_dir) self.work_dir = self.state.ctx.pipeline.work_dir @interceptable() diff --git a/src/engine/src/helpers/TemplateMapper.py b/src/engine/src/helpers/TemplateMapper.py index 437726da..c6be9292 100644 --- a/src/engine/src/helpers/TemplateMapper.py +++ b/src/engine/src/helpers/TemplateMapper.py @@ -39,7 +39,7 @@ def map(self, obj: Union[Pipeline, Task], uses: Uses) -> Union[Pipeline, Task]: # Resolve which class the final object should have obj_class = Pipeline if not issubclass(obj.__class__, Pipeline): - obj_class = self.task_map_by_type.get(obj.get("type"), None) + obj_class = self.task_map_by_type.get(obj.type, None) # Raise exception if no class could be resolved from the template if obj_class == None: @@ -47,6 +47,8 @@ def map(self, obj: Union[Pipeline, Task], uses: Uses) -> Union[Pipeline, Task]: dict_obj = obj.dict() + # Create a dictionary of the original object and map the properties of the template + # onto the dictionary for attr in template.keys(): # For pipelines only. Skip the tasks property as they should be handled # seperately in another call to the map method of the Template ampper @@ -59,18 +61,21 @@ def map(self, obj: Union[Pipeline, Task], uses: Uses) -> Union[Pipeline, Task]: dict_obj["type"] = template.get(attr) continue - if obj.get(attr, None) == None: + if getattr(obj, attr, None) == None: dict_obj[attr] = template[attr] + # Create a new object out of the modified dict representation of the original object new_obj = obj_class(**dict_obj) - for attr in vars(new_obj): + # Now add all of the properties to the original object from the new object. + # NOTE this allows us to return the exact same object that was passed as and + # argument but with the modifications, there by maintaining the objects identity. + for attr in new_obj.dict().keys(): if attr == "tasks": continue updated_value = getattr(new_obj, attr) - original_value = getattr(obj, attr) - if original_value != updated_value: + if getattr(obj, attr) != updated_value: setattr(obj, attr, updated_value) return obj \ No newline at end of file