Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(sdk/go): stop sending empty args on AddResource so pre-#2549 instances accept it#2878

Open
r266-tech wants to merge 1 commit into
volcengine:mainfrom
r266-tech:fix/gosdk-addresource-empty-args
Open

fix(sdk/go): stop sending empty args on AddResource so pre-#2549 instances accept it#2878
r266-tech wants to merge 1 commit into
volcengine:mainfrom
r266-tech:fix/gosdk-addresource-empty-args

Conversation

@r266-tech

Copy link
Copy Markdown
Contributor

Problem

AddResource (Go SDK) builds its request body with "args": map[string]any{} unconditionally, then only overrides it when opts.Args != nil. So when a caller passes no args — the common case, e.g. client.AddResource(ctx, path, nil) — an empty args object is always sent.

Instances that predate #2549 (which added the args field to the resources route under model_config = ConfigDict(extra="forbid")) have no args field, so extra="forbid" rejects the request with:

body.args: Extra inputs are not permitted

i.e. AddResource fails entirely against older / hosted OpenViking endpoints.

Fix

Drop the unconditional args: {} from the payload literal and only attach args when arguments were actually provided (len(opts.Args) > 0). This is the Go counterpart of the same cross-client backward-compat sweep already merged for the other surfaces:

Scope is intentionally args-only, matching #2834. All other fields, including directly_upload_media, are unchanged. The Go Find/Search paths already omit unset optionals via setString/setAny, so AddResource's empty args was the only remaining Go surface with this issue.

Note (intentional): len(opts.Args) > 0 treats nil and an explicitly-empty map[string]any{} the same — both omit the key. On this create route the server defaults args to {} (Field(default_factory=dict) from #2549), so "absent" and "present-but-empty" are equivalent; and omitting an explicit empty map is what keeps the request compatible with pre-#2549 instances. This mirrors _compact_request_body in #2834 (which is not used for PATCH/update bodies where null could mean "clear").

Tests

go test ./sdk/go passes. Added/extended coverage for all three arg states:

  • TestAddResourceUploadsLocalFile — asserts args is absent when the caller passes nil
  • TestAddResourceOmitsExplicitlyEmptyArgs — asserts args is absent for an explicitly-empty map
  • TestAddResourceSendsArgsWhenProvided — asserts args is forwarded when populated

AddResource unconditionally attached args: {} to every request body. Against
instances that predate volcengine#2549 (which added the args field to the resources
route under model_config=ConfigDict(extra="forbid")), the empty args object
is rejected with "body.args: Extra inputs are not permitted", so add-resource
fails entirely on older / hosted endpoints.

Only attach args when arguments were actually provided (len(opts.Args) > 0),
mirroring the Python SDK _compact_request_body (volcengine#2834) and the Rust CLI
compact_request_body (volcengine#2799). Other fields, including directly_upload_media,
are unchanged. Scope is args-only, matching volcengine#2834.

Tests cover the three arg states: omitted when unset, omitted when explicitly
empty (server defaults args to {} on this create route, so absent and
present-but-empty are equivalent), and forwarded when populated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant