Repository: AgnostiqHQ/covalent (language: python)

Issue:
Fix dynamic executor editing in Electrons
Tracking https://github.com/AgnostiqHQ/covalent/pull/1660#issuecomment-1559873222


Discussion / hints:
@kessler-frost I see that the fix is quite trivial to just add it directly inside the Electron object, could you pass a PR for this one ?

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8fd9cb980..1d74757b5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - Resolving correct python executable
 - Error handling for random URLs/random dispatchId entered on the GUI
+- Fixed support for dynamically assigning `executor` to `Electron` class
 
 ### Added
 
diff --git a/covalent/_workflow/electron.py b/covalent/_workflow/electron.py
index db6f168e5..0b217378d 100644
--- a/covalent/_workflow/electron.py
+++ b/covalent/_workflow/electron.py
@@ -641,7 +641,7 @@ def as_transportable_dict(self) -> Dict:
 # edit the class definition itself.
 Electron.executor = property(lambda self: self.get_metadata("executor"))
 Electron.executor = Electron.executor.setter(
-    lambda self, value: self.set_metadata("executor", value)
+    lambda self, value: self.metadata.update(encode_metadata({"executor": value}))
 )
 
 


Test patch:
diff --git a/tests/covalent_tests/workflow/electron_test.py b/tests/covalent_tests/workflow/electron_test.py
index 717679bd8..622c03cdb 100644
--- a/tests/covalent_tests/workflow/electron_test.py
+++ b/tests/covalent_tests/workflow/electron_test.py
@@ -496,6 +496,15 @@ def test_electron_executor_property():
     def mock_task():
         pass
 
+    mock_encoded_metadata = encode_metadata({"executor": LocalExecutor()})
+
     mock_task_electron = mock_task.electron_object
+
+    # If string is passed
     mock_task_electron.executor = "mock"
     assert mock_task_electron.metadata["executor"] == "mock"
+
+    # If executor object is passed
+    mock_task_electron.executor = LocalExecutor()
+    assert mock_task_electron.metadata["executor"] == mock_encoded_metadata["executor"]
+    assert mock_task_electron.metadata["executor_data"] == mock_encoded_metadata["executor_data"]