Fix SpaceRuntime parsing after volumes mutation API calls#4061
Open
Fix SpaceRuntime parsing after volumes mutation API calls#4061
Conversation
PUT/DELETE /spaces/.../volumes may return JSON without a top-level stage. HfApi.set_space_volumes and delete_space_volumes now fall back to get_space_runtime when the body is empty or not a full runtime payload. Made-with: Cursor
…allback Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Member
Member
Author
|
yup @davanstrien exactly, thanks for that PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Not sure if this is a problem with Hub server or library, but basically I've noticed that
PUT/DELETE/api/spaces/{repo_id}/volumescan return a JSON body that is not a full Space runtime document (e.g. only volume-related fields, no top-levelstage). The client always didreturn SpaceRuntime(r.json()), which raises whenstageis missing:Example of what goes wrong with the previous behavior:
This PR checks more resiliently if the response is empty or does not contain
"stage", in which case it falls back toget_space_runtime(repo_id)so callers still get a validSpaceRuntime.Noticed while testing the latest version of
huggingface_hub(1.9.1) withtrackioNote
Low Risk
Low risk: change is localized to Space volume mutation return handling and adds a unit test; main behavioral difference is an extra
get_space_runtimecall when the Hub response is empty or not parseable as a fullSpaceRuntime.Overview
Fixes
set_space_volumesanddelete_space_volumesto be resilient to Hub responses that don’t include a fullSpaceRuntimepayload. A new helper (_space_runtime_after_mutation) now attempts to parse the response when possible, but falls back toget_space_runtimewhen the body is empty or missing required fields.Adds a regression test ensuring that a non-runtime JSON response (e.g. only
{"volumes": [...]}) triggers the fallback fetch instead of raising duringSpaceRuntimeconstruction.Reviewed by Cursor Bugbot for commit 15ce06a. Bugbot is set up for automated code reviews on this repo. Configure here.