Skip to content

Fix set_space_volume / delete_space_volume return types#4061

Merged
Wauplin merged 6 commits intomainfrom
fix-space-volumes-runtime-response
Apr 8, 2026
Merged

Fix set_space_volume / delete_space_volume return types#4061
Wauplin merged 6 commits intomainfrom
fix-space-volumes-runtime-response

Conversation

@abidlabs
Copy link
Copy Markdown
Member

@abidlabs abidlabs commented Apr 7, 2026

🚨 This PR removes the returned value of both set_space_volumes and delete_space_volumes. This is a breaking change but in practice it never worked so it's more of a fix ^^

Not sure if this is a problem with Hub server or library, but basically I've noticed that PUT / DELETE /api/spaces/{repo_id}/volumes can return a JSON body that is not a full Space runtime document (e.g. only volume-related fields, no top-level stage). The client always did return SpaceRuntime(r.json()), which raises when stage is missing:

KeyError: 'stage'

Now working correctly with

from huggingface_hub import Volume, create_repo, delete_space_volumes, set_space_volumes

repo_id = create_repo(repo_id="my-cool-training-space", repo_type="space", space_sdk="gradio", exist_ok=True).repo_id
set_space_volumes(
    repo_id=repo_id,
    volumes=[Volume(type="model", source="openai-community/gpt2", mount_path="/gpt2", read_only=True)],
)
delete_space_volumes(repo_id=repo_id)

Noticed while testing the latest version of huggingface_hub (1.9.1) with trackio


Note

Medium Risk
This is a behavior/signature change for two public client methods and may break callers relying on the returned SpaceRuntime, though the logic change itself is small and localized.

Overview
Adjusts Space volume mutation APIs to no longer parse and return SpaceRuntime from PUT/DELETE /api/spaces/{repo_id}/volumes responses.

HfApi.set_space_volumes and HfApi.delete_space_volumes now return None and drop the documented return value, preventing SpaceRuntime(r.json()) failures when the server returns a partial body.

Reviewed by Cursor Bugbot for commit 029bedd. Bugbot is set up for automated code reviews on this repo. Configure here.

abidlabs added 4 commits April 7, 2026 09:44
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
@abidlabs abidlabs marked this pull request as ready for review April 7, 2026 16:52
@bot-ci-comment
Copy link
Copy Markdown

bot-ci-comment Bot commented Apr 7, 2026

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.

@davanstrien
Copy link
Copy Markdown
Member

Thanks for the fix! IIUC the response parsing issue has been there since the volumes API was first added in #4018, but it wasn't reachable until #4054 fixed the request payload format.

@abidlabs
Copy link
Copy Markdown
Member Author

abidlabs commented Apr 7, 2026

yup @davanstrien exactly, thanks for that PR!

@Wauplin Wauplin changed the title Fix SpaceRuntime parsing after volumes mutation API calls Fix set_space_volume / delete_space_volume return types Apr 8, 2026
Copy link
Copy Markdown
Contributor

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

(cc @hanouticelina if you can approve since I've written the PR)

@Wauplin
Copy link
Copy Markdown
Contributor

Wauplin commented Apr 8, 2026

Hey @abidlabs thanks for reporting and very sorry we've not tested this before shipping (my bad on this one 🙈 ). Simplest solution here is to return None and let the user make an additional call to get_space_runtime if they really want the current state. I've updated the PR changes and PR description to reflect that (I could have opened a separate PR but preferred to keep it here for viz')

Copy link
Copy Markdown
Contributor

@hanouticelina hanouticelina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@Wauplin Wauplin merged commit fa1718d into main Apr 8, 2026
15 of 21 checks passed
@Wauplin Wauplin deleted the fix-space-volumes-runtime-response branch April 8, 2026 08:39
Wauplin added a commit that referenced this pull request Apr 8, 2026
* fix: parse Space volumes mutation response or fetch runtime

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

* refactor: parse SpaceRuntime from mutation response with try/except fallback

Made-with: Cursor

* test: collapse Space volumes mutation tests into one case

Made-with: Cursor

* test: keep single Space volumes regression (non-runtime JSON payload)

Made-with: Cursor

* just return None

---------

Co-authored-by: Lucain Pouget <[email protected]>
@Wauplin
Copy link
Copy Markdown
Contributor

Wauplin commented Apr 8, 2026

Shipped in https://github.com/huggingface/huggingface_hub/releases/tag/v1.9.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants