Skip to content

Commit c02e181

Browse files
authored
internal: update GetResourceConfig to use dyn/convert rather than JSON roundtrip (#3646)
## Why For direct, we fetch configs as struct instances via GetResourceConfig, which is using json roundtrip between dyn value and struct. That, however, does not work well when there references in the config, see #3645 for details. This switches to converting dyn.Value with dyn/convert ToTyped function. The function was not used previously because it did not handle ForceSendFields correctly for embedded structs which caused JSON marshaller in Go SDK to return error. This was fixed in #3650 and #3649 ## Tests Existing tests.
1 parent be89cdb commit c02e181

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

bundle/config/root.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package config
33
import (
44
"bytes"
55
"context"
6-
"encoding/json"
76
"fmt"
87
"os"
98
"reflect"
@@ -609,14 +608,10 @@ func (r *Root) GetResourceConfig(path string) (any, bool) {
609608
return nil, false
610609
}
611610

612-
// json-round-trip into a value of the concrete resource type to ensure proper handling of ForceSendFields
613-
bytes, err := json.Marshal(v.AsAny())
614-
if err != nil {
615-
return nil, false
616-
}
617-
618611
typedConfigPtr := reflect.New(typ)
619-
if err := json.Unmarshal(bytes, typedConfigPtr.Interface()); err != nil {
612+
613+
err = convert.ToTyped(typedConfigPtr.Interface(), v)
614+
if err != nil {
620615
return nil, false
621616
}
622617

0 commit comments

Comments
 (0)