Skip to content

structaccess: two ForceSendFields fixes in Set - #6466

Merged
denik merged 3 commits into
mainfrom
denik/structaccess-forcesendfields
Sep 2, 2026
Merged

structaccess: two ForceSendFields fixes in Set#6466
denik merged 3 commits into
mainfrom
denik/structaccess-forcesendfields

Conversation

@denik

@denik denik commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Two independent bugs in Set:

  • ForceSendFields was updated before the assignment, so a value that could not be converted left the field's send-behaviour changed even though the Set failed. Setting an omitempty numeric field to "" recorded it as force-send and then failed.
  • Emptiness was judged from the caller's value, not the converted one, so an omitempty number set from the string "0" was stored as zero and left out of ForceSendFields — marshalled as absent. Latent today, since no value library writes a number as a quoted string.

Both tests fail without the fix.

This pull request and its description were written by Isaac.

Set updated ForceSendFields before assigning, so a value that could not be converted left
the field's send-behaviour changed even though the Set failed: setting an omitempty numeric
field to "" recorded the field as force-send and then failed the conversion. The assignment
goes first.

Co-authored-by: Isaac
Set converted the caller's value on the way in but judged emptiness from the value it was
handed, so an omitempty numeric or bool field set from a string that converts to zero was
stored as zero and then left out of ForceSendFields -- and marshalled as absent. Setting
max_concurrent_runs to "0" silently meant unset.

Latent today, since no value library writes a number as a quoted string, but it contradicts
the contract callers rely on: a scalar is left to structaccess to convert between the numeric
and string kinds.

Co-authored-by: Isaac
@denik
denik marked this pull request as ready for review September 1, 2026 19:20
@denik
denik enabled auto-merge September 1, 2026 19:22
Comment thread libs/structs/structaccess/set.go Outdated
err := updateForceSendFields(parentVal, sf.Name, embeddedIndex, valueVal, sf)
// Assign first: a value that cannot be converted must leave the struct exactly as it was,
// and updating ForceSendFields before the assignment left the field's send-behaviour
// changed after a failed Set.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment referring to previous state is irrelevant when you read it post-merge.

@denik
denik added this pull request to the merge queue Sep 2, 2026
@denik
denik removed this pull request from the merge queue due to a manual request Sep 2, 2026
Remove the phrase explaining the historical pre-fix state. The "assign first" comment
already says what matters.
@denik
denik enabled auto-merge September 2, 2026 06:12
@denik
denik added this pull request to the merge queue Sep 2, 2026
Merged via the queue into main with commit 90c4f45 Sep 2, 2026
26 checks passed
@denik
denik deleted the denik/structaccess-forcesendfields branch September 2, 2026 06:49
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