Repository: iterative/dvc
Pull request #9137 (2023-03-08 19:02:26)

studio: handle revision errors when posting
Context: I found this when testing out a https://github.com/iterative/dvclive/pull/464 in a repo with overlapping outputs (tracking the model as both a stage output and in a .dvc file).

Before this PR:

```
$ dvc exp run -f
DVC failed to load some parameters for following revisions: ''.
DVC failed to load some metrics for following revisions: ''.
ERROR: Failed to reproduce experiment '9dc4c70': 'data'
```

After this PR:

```
$ dvc exp run -f
DVC failed to load some parameters for following revisions: ''.
DVC failed to load some metrics for following revisions: ''.
ERROR: output 'model' is already specified in stages:
        - train
        - model.dvc
```

This still isn't a good UX, but at least now I can see a somewhat more useful error.

dberenbaum: Related: #8986
codecov[bot]: # [Codecov](https://codecov.io/gh/iterative/dvc/pull/9137?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative) Report
Patch coverage: **`100.00`**% and project coverage change: **`-0.44`** :warning:
> Comparison is base [(`48a63ca`)](https://codecov.io/gh/iterative/dvc/commit/48a63ca58832565a6e8d9448b1025746b1a76bd9?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative) 92.91% compared to head [(`3b35b1b`)](https://codecov.io/gh/iterative/dvc/pull/9137?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative) 92.47%.

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


```diff
@@            Coverage Diff             @@
##             main    #9137      +/-   ##
==========================================
- Coverage   92.91%   92.47%   -0.44%     
==========================================
  Files         456      456              
  Lines       36818    36821       +3     
  Branches     5312     5303       -9     
==========================================
- Hits        34208    34051     -157     
- Misses       2086     2200     +114     
- Partials      524      570      +46     
```


| [Impacted Files](https://codecov.io/gh/iterative/dvc/pull/9137?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative) | Coverage Δ | |
|---|---|---|
| [dvc/repo/experiments/utils.py](https://codecov.io/gh/iterative/dvc/pull/9137?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative#diff-ZHZjL3JlcG8vZXhwZXJpbWVudHMvdXRpbHMucHk=) | `82.28% <100.00%> (ø)` | |
| [tests/unit/repo/experiments/test\_utils.py](https://codecov.io/gh/iterative/dvc/pull/9137?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative#diff-dGVzdHMvdW5pdC9yZXBvL2V4cGVyaW1lbnRzL3Rlc3RfdXRpbHMucHk=) | `100.00% <100.00%> (ø)` | |
| [dvc/utils/threadpool.py](https://codecov.io/gh/iterative/dvc/pull/9137?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative#diff-ZHZjL3V0aWxzL3RocmVhZHBvb2wucHk=) | `63.04% <0.00%> (-30.44%)` | :arrow_down: |
| [tests/unit/test\_rwlock.py](https://codecov.io/gh/iterative/dvc/pull/9137?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative#diff-dGVzdHMvdW5pdC90ZXN0X3J3bG9jay5weQ==) | `77.52% <0.00%> (-22.48%)` | :arrow_down: |
| [tests/func/test\_unprotect.py](https://codecov.io/gh/iterative/dvc/pull/9137?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative#diff-dGVzdHMvZnVuYy90ZXN0X3VucHJvdGVjdC5weQ==) | `78.57% <0.00%> (-21.43%)` | :arrow_down: |
| [tests/unit/test\_api.py](https://codecov.io/gh/iterative/dvc/pull/9137?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative#diff-dGVzdHMvdW5pdC90ZXN0X2FwaS5weQ==) | `83.33% <0.00%> (-16.67%)` | :arrow_down: |
| [tests/unit/utils/test\_utils.py](https://codecov.io/gh/iterative/dvc/pull/9137?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative#diff-dGVzdHMvdW5pdC91dGlscy90ZXN0X3V0aWxzLnB5) | `83.33% <0.00%> (-16.67%)` | :arrow_down: |
| [tests/unit/test\_daemon.py](https://codecov.io/gh/iterative/dvc/pull/9137?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative#diff-dGVzdHMvdW5pdC90ZXN0X2RhZW1vbi5weQ==) | `85.18% <0.00%> (-14.82%)` | :arrow_down: |
| [dvc/utils/fs.py](https://codecov.io/gh/iterative/dvc/pull/9137?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative#diff-ZHZjL3V0aWxzL2ZzLnB5) | `83.63% <0.00%> (-10.91%)` | :arrow_down: |
| [tests/unit/utils/test\_fs.py](https://codecov.io/gh/iterative/dvc/pull/9137?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative#diff-dGVzdHMvdW5pdC91dGlscy90ZXN0X2ZzLnB5) | `88.42% <0.00%> (-9.48%)` | :arrow_down: |
| ... and [29 more](https://codecov.io/gh/iterative/dvc/pull/9137?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative) | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/iterative/dvc/pull/9137?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iterative).


Patch:
diff --git a/dvc/repo/experiments/utils.py b/dvc/repo/experiments/utils.py
index d6b5c22fd..8f3b2037b 100644
--- a/dvc/repo/experiments/utils.py
+++ b/dvc/repo/experiments/utils.py
@@ -337,7 +337,7 @@ def to_studio_params(dvc_params):
     if not dvc_params:
         return result
     for rev_data in dvc_params.values():
-        for file_name, file_data in rev_data["data"].items():
+        for file_name, file_data in rev_data.get("data", {}).items():
             result[file_name] = file_data["data"]
 
     return result


Test patch:
diff --git a/tests/unit/repo/experiments/test_utils.py b/tests/unit/repo/experiments/test_utils.py
index 1b6839ba0..1e93321fe 100644
--- a/tests/unit/repo/experiments/test_utils.py
+++ b/tests/unit/repo/experiments/test_utils.py
@@ -2,7 +2,7 @@ import pytest
 
 from dvc.exceptions import InvalidArgumentError
 from dvc.repo.experiments.refs import EXPS_NAMESPACE, ExpRefInfo
-from dvc.repo.experiments.utils import check_ref_format, resolve_name
+from dvc.repo.experiments.utils import check_ref_format, resolve_name, to_studio_params
 
 
 def commit_exp_ref(tmp_dir, scm, file="foo", contents="foo", name="foo"):
@@ -53,3 +53,20 @@ def test_run_check_ref_format(scm, name, result):
     else:
         with pytest.raises(InvalidArgumentError):
             check_ref_format(scm, ref)
+
+
+@pytest.mark.parametrize(
+    "params,expected",
+    [
+        (
+            {"workspace": {"data": {"params.yaml": {"data": {"foo": 1}}}}},
+            {"params.yaml": {"foo": 1}},
+        ),
+        (
+            {"workspace": {"error": "something went wrong"}},
+            {},
+        ),
+    ],
+)
+def test_to_studio_params(params, expected):
+    assert to_studio_params(params) == expected