Conversation
3 tasks
tas50
force-pushed
the
fix/dig-nested-attributes
branch
3 times, most recently
from
September 8, 2026 16:53
38459c2 to
f31fe84
Compare
5 tasks
A Go type assertion matches the dynamic type exactly, so asserting to
map[string]any never matched an Attributes value even though the two share
an underlying type. Dig only worked at the top level, where it converts
explicitly; one level down it gave up:
n := &Node{Normal: Attributes{"network": Attributes{"gw": "10.0.0.1"}}}
n.Attribute("network.gw") // nil, false
JSON-decoded nodes were unaffected - encoding/json only ever produces
map[string]any - which is why no test caught it. Any attribute tree built
in Go silently reported "not found", through Dig, GetString, Attribute and
AttributeString alike.
Unwrap both shapes.
Signed-off-by: Tim Smith <tim@mondoo.com>
tas50
force-pushed
the
fix/dig-nested-attributes
branch
from
September 10, 2026 16:37
f31fe84 to
ab91c24
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.
Attributes.Digasserted each level tomap[string]any. A Go type assertion matches the dynamic type exactly, so it never matched anAttributesvalue — even though the two share an underlying type and convert freely.Digtherefore only worked at the top level, where it converts explicitly (var cur any = map[string]any(a)). One level down:JSON-decoded nodes were unaffected, because
encoding/jsononly ever producesmap[string]any— which is exactly why the existing tests missed it. But any attribute tree built in Go silently reported "not found", throughDig,GetString,AttributeandAttributeStringalike.Fixed by unwrapping both shapes in one helper.
Test plan
TestDig_TraversesNestedAttributes— two levels ofAttributes, viaDigandGetStringTestNodeAttribute_TraversesNestedAttributes— via theNodeprecedence lookupDig = <nil>, false)map[string]anypath is unchangedgo vet ./...cleango test ./... -race -count=2