Skip to content

Commit

Permalink
bugfix: use correct accessors for template object
Browse files Browse the repository at this point in the history
  • Loading branch information
nathandf committed Oct 18, 2023
1 parent 3c93b6f commit cec5cb8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/engine/src/core/workflows/executors/WorkflowExecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 10 additions & 5 deletions src/engine/src/helpers/TemplateMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ 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:
raise Exception(f"Invalid Template: Unable to resolve object type from Template. Task template object 'type' property must be one of [{self.task_map_by_type.keys()}]")

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
Expand All @@ -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

0 comments on commit cec5cb8

Please sign in to comment.