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
Open
fix(sdk/go): stop sending empty args on AddResource so pre-#2549 instances accept it#2878r266-tech wants to merge 1 commit into
r266-tech wants to merge 1 commit into
Conversation
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.
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.
Problem
AddResource(Go SDK) builds its request body with"args": map[string]any{}unconditionally, then only overrides it whenopts.Args != nil. So when a caller passes no args — the common case, e.g.client.AddResource(ctx, path, nil)— an emptyargsobject is always sent.Instances that predate #2549 (which added the
argsfield to the resources route undermodel_config = ConfigDict(extra="forbid")) have noargsfield, soextra="forbid"rejects the request with:i.e.
AddResourcefails entirely against older / hosted OpenViking endpoints.Fix
Drop the unconditional
args: {}from the payload literal and only attachargswhen 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:compact_request_body)_compact_request_body)Scope is intentionally
args-only, matching #2834. All other fields, includingdirectly_upload_media, are unchanged. The GoFind/Searchpaths already omit unset optionals viasetString/setAny, soAddResource's emptyargswas the only remaining Go surface with this issue.Note (intentional):
len(opts.Args) > 0treatsniland an explicitly-emptymap[string]any{}the same — both omit the key. On this create route the server defaultsargsto{}(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_bodyin #2834 (which is not used for PATCH/update bodies wherenullcould mean "clear").Tests
go test ./sdk/gopasses. Added/extended coverage for all three arg states:TestAddResourceUploadsLocalFile— assertsargsis absent when the caller passesnilTestAddResourceOmitsExplicitlyEmptyArgs— assertsargsis absent for an explicitly-empty mapTestAddResourceSendsArgsWhenProvided— assertsargsis forwarded when populated