Repository: AgnostiqHQ/covalent
Pull request #1600 (2023-04-25 20:54:57)

raise error on dispatching a non-lattice
<!--
⚠️ 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.
-->

Fixes https://github.com/AgnostiqHQ/covalent/issues/793

- [x] I have added the tests to cover my changes.
- [x] I have updated the documentation and CHANGELOG accordingly.
- [x] I have read the CONTRIBUTING document.


madhur-tandon: CC: @santoshkumarradha @AlejandroEsquivel 
codecov[bot]: ## [Codecov](https://codecov.io/gh/AgnostiqHQ/covalent/pull/1600?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) Report
> Merging [#1600](https://codecov.io/gh/AgnostiqHQ/covalent/pull/1600?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) (926fa58) into [develop](https://codecov.io/gh/AgnostiqHQ/covalent/commit/c72ab6a2ed091bbca1d4847fbe6df6e8be4d2d8f?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) (c72ab6a) will **increase** coverage by `1.05%`.
> 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/1600/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/1600?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ)

```diff
@@             Coverage Diff             @@
##           develop    #1600      +/-   ##
===========================================
+ Coverage    85.91%   86.97%   +1.05%     
===========================================
  Files          159       83      -76     
  Lines         6646     4960    -1686     
  Branches       145        0     -145     
===========================================
- Hits          5710     4314    -1396     
+ Misses         834      646     -188     
+ Partials       102        0     -102     
```

| Flag | Coverage Δ | | *Carryforward flag |
|---|---|---|---|
| Dispatcher | `87.28% <ø> (ø)` | | Carriedforward from [c72ab6a](https://codecov.io/gh/AgnostiqHQ/covalent/commit/c72ab6a2ed091bbca1d4847fbe6df6e8be4d2d8f?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) |
| Functional_Tests | `?` | | |
| SDK | `86.78% <100.00%> (+0.14%)` | :arrow_up: | |
| UI_Frontend | `?` | | |

*This pull request uses carry forward flags. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) to find out more.

</details>
madhur-tandon: @kessler-frost seems like `license/cla` is stuck?
kessler-frost: Yeah, I wouldn't worry about it, it should get done soon. Automerge is enabled so once these checks pass this will get merged automatically.
madhur-tandon: > Yeah, I wouldn't worry about it, it should get done soon. 

I think you might have to re-trigger this because I don't remember this taking so long... 😅 
madhur-tandon: @kessler-frost I think you triggered `license` while it should have been `license/cla` i.e. the contributor's license agreement.
kessler-frost: Yeah I just realized that, my bad. Can you try making another commit on this one? That usually fixes it.
kessler-frost: Yep, that fixed it, thanks! (For some reason I couldn't find that action 🤔 )

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 07d72e5d..d915e052 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [UNRELEASED]
 
+### Fixed
+
+- Raise error on dispatching a non-lattice
+
+### Authors
+
+- Madhur Tandon <madhurtandon23@gmail.com>
+
 ### Operations
 
 - Removed "already released" check from stable changelog action
@@ -19,7 +27,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - Co-authored-by: kessler-frost <ssanand@hawk.iit.edu>
 - Co-authored-by: Alejandro Esquivel <ae@alejandro.ltd>
 
-
 ### Changed
 
 - Implementation of `TransportableObject` property method to be backwards compatible with version 0.209.1.
diff --git a/covalent/_dispatcher_plugins/local.py b/covalent/_dispatcher_plugins/local.py
index ac6177d5..63d9707c 100644
--- a/covalent/_dispatcher_plugins/local.py
+++ b/covalent/_dispatcher_plugins/local.py
@@ -122,6 +122,11 @@ class LocalDispatcher(BaseDispatcher):
             # To access the disable_run passed to the dispatch function
             nonlocal disable_run
 
+            if not isinstance(orig_lattice, Lattice):
+                message = f"Dispatcher expected a Lattice, received {type(orig_lattice)} instead."
+                app_log.error(message)
+                raise TypeError(message)
+
             lattice = deepcopy(orig_lattice)
 
             lattice.build_graph(*args, **kwargs)


Test patch:
diff --git a/tests/covalent_tests/dispatcher_plugins/local_test.py b/tests/covalent_tests/dispatcher_plugins/local_test.py
index 95a626c3..7ffec6b9 100644
--- a/tests/covalent_tests/dispatcher_plugins/local_test.py
+++ b/tests/covalent_tests/dispatcher_plugins/local_test.py
@@ -101,3 +101,21 @@ def test_redispatch(mocker, replace_electrons, expected_arg, is_pending):
     requests_mock.post().content.decode().strip().replace.assert_called_once_with('"', "")
 
     get_request_body_mock.assert_called_once_with("mock-dispatch-id", (), {}, expected_arg, False)
+
+
+def test_dispatching_a_non_lattice():
+    """test dispatching a non-lattice"""
+
+    @ct.electron
+    def task(a, b, c):
+        return a + b + c
+
+    @ct.electron
+    @ct.lattice
+    def workflow(a, b):
+        return task(a, b, c=4)
+
+    with pytest.raises(
+        TypeError, match="Dispatcher expected a Lattice, received <class 'function'> instead."
+    ):
+        LocalDispatcher.dispatch(workflow)(1, 2)