Repository: AgnostiqHQ/covalent
Pull request #1267 (2022-09-22 14:07:52)

Remove DB dependency from sync
<!--
⚠️ 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.
-->

- [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.


codecov[bot]: # [Codecov](https://codecov.io/gh/AgnostiqHQ/covalent/pull/1267?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) Report
> Merging [#1267](https://codecov.io/gh/AgnostiqHQ/covalent/pull/1267?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) (368bf3d) into [develop](https://codecov.io/gh/AgnostiqHQ/covalent/commit/b1a14b7d0bcd27bf8f59e13914bba9353200aac1?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) (b1a14b7) will **decrease** coverage by `4.38%`.
> The diff coverage is `93.84%`.

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


[![Impacted file tree graph](https://codecov.io/gh/AgnostiqHQ/covalent/pull/1267/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/1267?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ)

```diff
@@             Coverage Diff             @@
##           develop    #1267      +/-   ##
===========================================
- Coverage    86.45%   82.06%   -4.39%     
===========================================
  Files           59       62       +3     
  Lines         3816     3808       -8     
===========================================
- Hits          3299     3125     -174     
- Misses         517      683     +166     
```

| Flag | Coverage Δ | | *Carryforward flag |
|---|---|---|---|
| Dispatcher | `78.07% <91.60%> (+2.92%)` | :arrow_up: | Carriedforward from [4a40aa3](https://codecov.io/gh/AgnostiqHQ/covalent/commit/4a40aa3d96e6c1f588980fcd87b5351eb87ffe4b?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) |
| Functional_Tests | `?` | | |
| SDK | `83.34% <94.73%> (+3.81%)` | :arrow_up: | |

*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>
cjao: Codecov bug should be fixed by #1252 

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 543ebac7..0795b417 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - Fixed `asserts` in stress tests
 - Added unit tests for `defaults.py`
+- Updated `test_sync()` to match the new function signature.
 
 ### Added
 
@@ -29,6 +30,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - Updated `requirements.txt` and `tests/requirements.txt`
 - Updated `nbconvert` by dependabot
 
+### Removed
+
+- The DB dependency in `sync()`
+- The ability for `sync()` to wait for all dispatches.
+
 ### Docs
 
 - Fixed a notebook which was not rendering
diff --git a/covalent/_results_manager/results_manager.py b/covalent/_results_manager/results_manager.py
index b3cb98de..359bfae7 100644
--- a/covalent/_results_manager/results_manager.py
+++ b/covalent/_results_manager/results_manager.py
@@ -26,11 +26,9 @@ from typing import Dict, List, Optional, Union
 import cloudpickle as pickle
 import requests
 from requests.adapters import HTTPAdapter
-from sqlalchemy.orm import Session
 from urllib3.util import Retry
 
 from .. import _workflow as ct
-from .._data_store.datastore import DataStore
 from .._data_store.models import Lattice
 from .._shared_files import logger
 from .._shared_files.config import get_config
@@ -276,7 +274,6 @@ def redispatch_result(result_object: Result, dispatcher: str = None) -> str:
 
 
 def sync(
-    db: DataStore,
     dispatch_id: Optional[Union[List[str], str]] = None,
 ) -> None:
     """
@@ -295,10 +292,9 @@ def sync(
         for d in dispatch_id:
             _get_result_from_dispatcher(d, wait=True, status_only=True)
     else:
-        with Session(db.engine) as session:
-            rows = session.query(Lattice).all()
-        for row in rows:
-            _get_result_from_dispatcher(row.dispatch_id, wait=True, status_only=True)
+        raise Exception(
+            f"dispatch_id must be a string or a list. You passed a {type(dispatch_id)}."
+        )
 
 
 def cancel(


Test patch:
diff --git a/tests/covalent_tests/results_manager_tests/results_manager_test.py b/tests/covalent_tests/results_manager_tests/results_manager_test.py
index e422a16b..c2c3b8da 100644
--- a/tests/covalent_tests/results_manager_tests/results_manager_test.py
+++ b/tests/covalent_tests/results_manager_tests/results_manager_test.py
@@ -124,17 +124,15 @@ def test_sync(lattice_record, mocker, tmp_path):
     db = MockDataStore(lattice_record, tmp_path)
 
     dispatch_id = "9d1b308b-4763-4990-ae7f-6a6e36d35893"
-    sync(db, dispatch_id)
+    sync(dispatch_id)
     mock_get_result_from_dispatcher.assert_called_once_with(
         dispatch_id, wait=True, status_only=True
     )
     mock_get_result_from_dispatcher.reset_mock()
     dispatch_ids = ["f34671d1-48f2-41ce-89d9-9a8cb5c60e5d", "02dfd929-d96b-4ad1-8411-a818ce465169"]
-    sync(db, dispatch_ids)
+    sync(dispatch_ids)
     for dispatch_id in dispatch_ids:
         mock_get_result_from_dispatcher.assert_any_call(dispatch_id, wait=True, status_only=True)
     mock_get_result_from_dispatcher.reset_mock()
-    sync(db)
-    mock_get_result_from_dispatcher.assert_called_once_with(
-        DISPATCH_ID, wait=True, status_only=True
-    )
+    with pytest.raises(Exception):
+        sync(1)