fix(datasets): improve get_safe_version raise (#4263)

* fix: Pass the required response argument to RevisionNotFoundError

* chore(dataset): get_safe_version raise

---------

Co-authored-by: Harshal Janjani <harshaljanjani@gmail.com>
This commit is contained in:
Steven Palma
2026-07-31 14:13:14 +02:00
committed by GitHub
parent 8e2a077f09
commit 0a4510c74e
2 changed files with 30 additions and 13 deletions
+13 -13
View File
@@ -26,7 +26,6 @@ import numpy as np
import packaging.version import packaging.version
import torch import torch
from huggingface_hub import DatasetCard, DatasetCardData, HfApi from huggingface_hub import DatasetCard, DatasetCardData, HfApi
from huggingface_hub.errors import RevisionNotFoundError
from lerobot.utils.utils import flatten_dict, unflatten_dict from lerobot.utils.utils import flatten_dict, unflatten_dict
@@ -51,6 +50,17 @@ The dataset you requested ({repo_id}) is only available in {version} format.
As we cannot ensure forward compatibility with it, please update your current version of lerobot. As we cannot ensure forward compatibility with it, please update your current version of lerobot.
""" """
MISSING_VERSION_TAG_MESSAGE = """
Your dataset must be tagged with a codebase version.
Assuming _version_ is the codebase_version value in the info.json, you can run this:
```python
from huggingface_hub import HfApi
hub_api = HfApi()
hub_api.create_tag("{repo_id}", tag="_version_", repo_type="dataset")
```
"""
class CompatibilityError(Exception): ... class CompatibilityError(Exception): ...
@@ -368,7 +378,7 @@ def get_safe_version(
str: The safe version string (e.g., "v1.2.3") to use as a revision. str: The safe version string (e.g., "v1.2.3") to use as a revision.
Raises: Raises:
RevisionNotFoundError: If the repo has no version tags. RuntimeError: If the repo has no version tags.
BackwardCompatibilityError: If only older major versions are available. BackwardCompatibilityError: If only older major versions are available.
ForwardCompatibilityError: If only newer major versions are available. ForwardCompatibilityError: If only newer major versions are available.
""" """
@@ -378,17 +388,7 @@ def get_safe_version(
hub_versions = get_repo_versions(repo_id) if token is None else get_repo_versions(repo_id, token=token) hub_versions = get_repo_versions(repo_id) if token is None else get_repo_versions(repo_id, token=token)
if not hub_versions: if not hub_versions:
raise RevisionNotFoundError( raise RuntimeError(MISSING_VERSION_TAG_MESSAGE.format(repo_id=repo_id))
f"""Your dataset must be tagged with a codebase version.
Assuming _version_ is the codebase_version value in the info.json, you can run this:
```python
from huggingface_hub import HfApi
hub_api = HfApi()
hub_api.create_tag("{repo_id}", tag="_version_", repo_type="dataset")
```
"""
)
if target_version in hub_versions: if target_version in hub_versions:
return f"v{target_version}" return f"v{target_version}"
+17
View File
@@ -180,3 +180,20 @@ def test_non_dict_passthrough_last_wins():
out = combine_feature_dicts(g1, g2) out = combine_feature_dicts(g1, g2)
# For non-dict entries the last one wins # For non-dict entries the last one wins
assert out["misc"] == 456 assert out["misc"] == 456
def test_get_safe_version_raises_on_repo_without_version_tags(monkeypatch):
monkeypatch.setattr(dataset_utils, "get_repo_versions", Mock(return_value=[]))
with pytest.raises(RuntimeError, match="must be tagged with a codebase version"):
get_safe_version("private/repo", "v3.0")
def test_get_safe_version_error_reports_repo_id(monkeypatch):
repo_id = "private/repo"
monkeypatch.setattr(dataset_utils, "get_repo_versions", Mock(return_value=[]))
with pytest.raises(RuntimeError) as exc_info:
get_safe_version(repo_id, "v3.0")
assert repo_id in str(exc_info.value)