structaccess: reach fields of a doubly-embedded struct - #6467
Draft
denik wants to merge 4 commits into
Draft
Conversation
This was referenced Sep 1, 2026
FindStructFieldByKeyType already recursed into embedded structs, but Get and Set stopped after one level, so a field of resources.PostgresProject -- which embeds a config struct that embeds the SDK spec -- was reported as not found. Both now walk embedding recursively and track the struct that declares the field, which is also the one whose ForceSendFields governs it: an outer struct that shadows the name (PostgresProjectConfig) tracks only its own fields. Co-authored-by: Isaac
… does From the adversarial review. Get and Set searched embedded structs depth-first, so a name declared at two embedding depths could resolve to the deeper field -- while json.Marshal picks the shallower one. Reading and writing the field would then not be the field that gets serialized under that name. The search now goes one level of embedding at a time, and the test fails on the old behaviour. Co-authored-by: Isaac
…tree Follow-up to the earlier fix, which only separated the first level of embedding from the rest: a field three levels down in the first anonymous member still won over the same name two levels down in a later member, while encoding/json picks the shallower one. ValidatePattern had the same depth-first walk, so a path could validate against one field and then be read and written on another. Both now walk level by level and share the direct-field scan. Co-authored-by: Isaac
The ForceSendFields assertion reads the promoted field, and the comparison spells out that GetByString returns the empty string rather than nil -- an explicit "" and an absent field are not the same thing.
denik
force-pushed
the
denik/structaccess-embedded-lookup
branch
from
September 2, 2026 09:40
7cb774c to
79f9b61
Compare
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.
The value-level field lookup descended one level into embedded structs, so a field two levels down was reported "not found" — every postgres resource has that shape (
PostgresProject→PostgresProjectConfig→postgres.ProjectSpec). The type-level lookup was already recursive, soValidatePathandGetdisagreed.The search is breadth-first, matching
encoding/json: JSON picks the shallowest field of a given name, so a depth-first search could resolve a path to a deeper field than the one that gets serialized.No product path reaches this today — the direct engine reads fields out of the state and remote types, where spec fields sit one level down.
bundle/internal/schema/parser.goandlibs/dyn/convert/struct_info.goalready walk past level 1 for exactly this shape; structaccess was the holdout.This pull request and its description were written by Isaac.