diff --git a/src/huggingface_hub/_space_api.py b/src/huggingface_hub/_space_api.py index ce07fca098..711ad50070 100644 --- a/src/huggingface_hub/_space_api.py +++ b/src/huggingface_hub/_space_api.py @@ -116,10 +116,10 @@ class SpaceRuntime: def __init__(self, data: Dict) -> None: self.stage = data["stage"] - self.hardware = data["hardware"]["current"] - self.requested_hardware = data["hardware"]["requested"] - self.sleep_time = data["gcTimeout"] - self.storage = data["storage"] + self.hardware = data.get("hardware", {}).get("current") + self.requested_hardware = data.get("hardware", {}).get("requested") + self.sleep_time = data.get("gcTimeout") + self.storage = data.get("storage") self.raw = data diff --git a/tests/test_hf_api.py b/tests/test_hf_api.py index b98b30fc9f..6d6fe9ab21 100644 --- a/tests/test_hf_api.py +++ b/tests/test_hf_api.py @@ -2540,6 +2540,14 @@ def test_space_runtime(self) -> None: # Raw response from Hub self.assertIsInstance(runtime.raw, dict) + def test_static_space_runtime(self) -> None: + """ + Regression test for static Spaces. + See https://github.com/huggingface/huggingface_hub/pull/1754. + """ + runtime = self.api.get_space_runtime("victor/static-space") + self.assertIsInstance(runtime.raw, dict) + def test_pause_and_restart_space(self) -> None: # Upload a fake app.py file self.api.upload_file(path_or_fileobj=b"", path_in_repo="app.py", repo_id=self.repo_id, repo_type="space")