Skip to content

Fix set_space_volumes sending bare array instead of object#4054

Merged
hanouticelina merged 1 commit intomainfrom
fix/set-space-volumes-payload
Apr 6, 2026
Merged

Fix set_space_volumes sending bare array instead of object#4054
hanouticelina merged 1 commit intomainfrom
fix/set-space-volumes-payload

Conversation

@davanstrien
Copy link
Copy Markdown
Member

@davanstrien davanstrien commented Apr 6, 2026

What does this PR do?

Fixes set_space_volumes which currently sends a bare JSON array to PUT /api/spaces/{repo_id}/volumes, but the endpoint expects a JSON object with a "volumes" key.

Before (fails with 400):

payload = [vol.to_dict() for vol in volumes]
# Sends: [{"type": "bucket", "source": "...", "mountPath": "...", ...}]

After (works):

payload = {"volumes": [vol.to_dict() for vol in volumes]}
# Sends: {"volumes": [{"type": "bucket", "source": "...", "mountPath": "...", ...}]}

How was this found?

Calling api.set_space_volumes() returns:

huggingface_hub.errors.BadRequestError: Invalid input: expected object, received array

How was the fix verified?

I tested both payload formats directly against the production endpoint:

# Bare array → 400 Bad Request
session.put(url, headers=headers, json=[{...}])

# Wrapped object → 200 OK, volume mounted successfully
session.put(url, headers=headers, json={"volumes": [{...}]})

Caveat

I inferred the expected payload format from the error message and empirical testing. I didn't check the server-side API spec, so it's possible the fix should be on the server side (accepting arrays) rather than the client side. Happy to adjust if the intended contract is different from what I've assumed here.


Note

Low Risk
Low risk, single-request payload shape change to match the server contract for PUT /api/spaces/{repo_id}/volumes. Main risk is compatibility if any server deployment previously accepted a bare array.

Overview
Fixes HfApi.set_space_volumes to wrap the serialized volumes list in a JSON object ({"volumes": [...]}) instead of sending a bare array, aligning the client payload with what PUT /api/spaces/{repo_id}/volumes expects.

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

The PUT /api/spaces/{repo_id}/volumes endpoint expects a JSON object
with a "volumes" key, but the client was sending a bare JSON array.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@bot-ci-comment
Copy link
Copy Markdown

bot-ci-comment Bot commented Apr 6, 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.

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.

thanks for fixing it!

for reference, the input specs for /api/:repoType(spaces)/:namespace/:repo/volumes are here (private link).

@hanouticelina hanouticelina merged commit 6983a4d into main Apr 6, 2026
19 of 35 checks passed
@hanouticelina hanouticelina deleted the fix/set-space-volumes-payload branch April 6, 2026 13:56
hanouticelina pushed a commit that referenced this pull request Apr 7, 2026
The PUT /api/spaces/{repo_id}/volumes endpoint expects a JSON object
with a "volumes" key, but the client was sending a bare JSON array.

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
@hanouticelina
Copy link
Copy Markdown
Contributor

we've just released a patch huggingface_hub==1.9.1 with the fix, thanks again for the PR! https://github.com/huggingface/huggingface_hub/releases/tag/v1.9.1

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.

2 participants