Repository: AgnostiqHQ/covalent
Pull request #1511 (2023-02-10 20:47:03)

Fix redispatch bug
- Fix redispatch bug and add functional tests to catch this failure in the future.

<!--
⚠️ Your pull request title should be short detailed and understandable for all.
⚠️ Increment the version number in the /VERSION file. If this is a bugfix, increment the patch version (the rightmost number), for example 0.18.2 becomes 0.18.3. If it's a new feature, increment the minor version (the middle number), for example 0.18.2 becomes 0.19.0.
⚠️ Add a note to /CHANGELOG.md with your version number and the date, summarizing the changes.
⚠️ If your pull request fixes an open issue, please link to the issue.
⚠️ Rebase the latest changes from the develop branch. Assuming origin points to https://github.com/AgnostiqHQ/covalent, you should run git rebase origin/develop.
-->

- [ ] I have added the tests to cover my changes.
- [ ] I have updated the documentation and CHANGELOG accordingly.
- [ ] I have read the CONTRIBUTING document.


github-actions[bot]: Hello. You may have forgotten to update the changelog!
Please edit [`CHANGELOG.md`](/AgnostiqHQ/covalent/blob/master/CHANGELOG.md) with a one-to-two sentence description of the change in the UNRELEASED section. You may include a small working example for new features.
codecov[bot]: # [Codecov](https://codecov.io/gh/AgnostiqHQ/covalent/pull/1511?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) Report
> Merging [#1511](https://codecov.io/gh/AgnostiqHQ/covalent/pull/1511?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) (95c6364) into [develop](https://codecov.io/gh/AgnostiqHQ/covalent/commit/ea53944d378cc846527e92ef141ea2880e353758?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) (ea53944) will **not change** coverage.
> The diff coverage is `100.00%`.

<details><summary>Additional details and impacted files</summary>


[![Impacted file tree graph](https://codecov.io/gh/AgnostiqHQ/covalent/pull/1511/graphs/tree.svg?width=650&height=150&src=pr&token=YGHCB3DE4P&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ)](https://codecov.io/gh/AgnostiqHQ/covalent/pull/1511?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ)

```diff
@@           Coverage Diff            @@
##           develop    #1511   +/-   ##
========================================
  Coverage    85.07%   85.07%           
========================================
  Files          146      146           
  Lines         5936     5936           
  Branches       145      145           
========================================
  Hits          5050     5050           
  Misses         784      784           
  Partials       102      102           
```

| Flag | Coverage Δ | |
|---|---|---|
| Dispatcher | `88.66% <100.00%> (ø)` | |
| Functional_Tests | `59.72% <0.00%> (ø)` | |
| SDK | `83.15% <ø> (ø)` | |
| UI_Frontend | `72.13% <ø> (ø)` | |

</details>

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3c6b69e5..ecaa83c5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [UNRELEASED]
 
+### Fixed
+
+- Redispatch bug.
+
 ### Changed
 
 - Location of function to load result from the database now moved to load module in covalent_dispatcher/_db folde.
diff --git a/covalent_dispatcher/_core/data_manager.py b/covalent_dispatcher/_core/data_manager.py
index 64e66b48..6303aef0 100644
--- a/covalent_dispatcher/_core/data_manager.py
+++ b/covalent_dispatcher/_core/data_manager.py
@@ -158,7 +158,7 @@ def _get_result_object_from_new_lattice(
         tg = result_object.lattice.transport_graph
         tg_old = old_result_object.lattice.transport_graph
         reusable_nodes = TransportGraphOps(tg_old).get_reusable_nodes(tg)
-        TransportGraphOps(tg_old).copy_nodes(tg, reusable_nodes)
+        TransportGraphOps(tg_old).copy_nodes_from(tg, reusable_nodes)
 
     return result_object
 


Test patch:
diff --git a/tests/covalent_dispatcher_tests/_core/data_manager_test.py b/tests/covalent_dispatcher_tests/_core/data_manager_test.py
index 54481a57..99f0f55c 100644
--- a/tests/covalent_dispatcher_tests/_core/data_manager_test.py
+++ b/tests/covalent_dispatcher_tests/_core/data_manager_test.py
@@ -187,14 +187,14 @@ def test_get_result_object_from_new_lattice(mocker, reuse):
         transport_graph_ops_mock().get_reusable_nodes.assert_called_with(
             result_object_mock().lattice.transport_graph
         )
-        transport_graph_ops_mock().copy_nodes.assert_called_once_with(
+        transport_graph_ops_mock().copy_nodes_from.assert_called_once_with(
             result_object_mock().lattice.transport_graph,
             transport_graph_ops_mock().get_reusable_nodes.return_value,
         )
 
     else:
         transport_graph_ops_mock().get_reusable_nodes.assert_not_called()
-        transport_graph_ops_mock().copy_nodes.assert_not_called()
+        transport_graph_ops_mock().copy_nodes_from.assert_not_called()
 
 
 @pytest.mark.parametrize("reuse", [True, False])
diff --git a/tests/covalent_tests/workflow/transport_graph_ops_test.py b/tests/covalent_tests/workflow/transport_graph_ops_test.py
index 20bb758e..80cbbe39 100644
--- a/tests/covalent_tests/workflow/transport_graph_ops_test.py
+++ b/tests/covalent_tests/workflow/transport_graph_ops_test.py
@@ -146,7 +146,7 @@ def test_is_same_edge_attributes_false(tg, tg_ops):
     assert tg_ops.is_same_edge_attributes(tg._graph, tg_2._graph, 0, 1) is False
 
 
-def test_copy_nodes(tg_ops):
+def test_copy_nodes_from(tg_ops):
     """Test the node copying method."""
 
     def replacement(x):
diff --git a/tests/functional_tests/workflow_stack_test.py b/tests/functional_tests/workflow_stack_test.py
index 36a48ff3..6853f2f4 100644
--- a/tests/functional_tests/workflow_stack_test.py
+++ b/tests/functional_tests/workflow_stack_test.py
@@ -931,3 +931,30 @@ def test_redispatch_reusing_previous_results():
         assert (
             res_obj_3.get_node_result(i)["start_time"] == res_obj_3.get_node_result(i)["end_time"]
         )
+
+
+def test_redispatch_reusing_previous_results_and_new_args():
+    """Test reusing previous results for redispatching and using new args."""
+
+    @ct.electron
+    def task_1(x):
+        return x
+
+    @ct.electron
+    def failing_task(x, y):
+        return x / y
+
+    @ct.lattice
+    def failing_workflow(x, y):
+        res_1 = task_1(x)
+        return failing_task(res_1, y)
+
+    dispatch_id = ct.dispatch(failing_workflow)(1, 0)
+    result = ct.get_result(dispatch_id, wait=True)
+    assert result.result is None
+    assert str(result.status) == "FAILED"
+
+    redispatch_id = ct.redispatch(dispatch_id=dispatch_id, reuse_previous_results=True)(1, 1)
+    result = ct.get_result(redispatch_id, wait=True)
+    assert int(result.result) == 1
+    assert str(result.status) == "COMPLETED"