From 8cf7858cb668563959b641fc11727bbff37bbc16 Mon Sep 17 00:00:00 2001 From: Casey Jao Date: Sun, 26 May 2024 14:34:58 -0400 Subject: [PATCH] Handle Covalent version mismatches more gracefully Accessing electron attributes directly in `Electron.__call__` can cause problems if those attributes happen to be missing. --- covalent/_workflow/electron.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/covalent/_workflow/electron.py b/covalent/_workflow/electron.py index 0e80f0a22..730a9be82 100644 --- a/covalent/_workflow/electron.py +++ b/covalent/_workflow/electron.py @@ -429,6 +429,11 @@ def __call__(self, *args, **kwargs) -> Union[Any, "Electron"]: active_lattice.replace_electrons[name] = replacement_electron return bound_electron + # Avoid direct attribute access since that might trigger + # Electron.__getattr__ when executors build sublattices + # constructed with older versions of Covalent + function_string = self.__dict__.get("_function_string") + # Handle sublattices by injecting _build_sublattice_graph node if isinstance(self.function, Lattice): parent_metadata = active_lattice.metadata.copy() @@ -443,7 +448,6 @@ def __call__(self, *args, **kwargs) -> Union[Any, "Electron"]: ) name = sublattice_prefix + self.function.__name__ - function_string = self._function_string bound_electron = sub_electron( self.function, json.dumps(parent_metadata), *args, **kwargs ) @@ -464,7 +468,7 @@ def __call__(self, *args, **kwargs) -> Union[Any, "Electron"]: name=self.function.__name__, function=self.function, metadata=self.metadata.copy(), - function_string=self._function_string, + function_string=function_string, task_group_id=self.task_group_id if self.packing_tasks else None, ) self.task_group_id = self.task_group_id if self.packing_tasks else self.node_id