Skip to content

Commit a3c6424

Browse files
direct: document the top-level-field constraint of CompactState's shallow copy
The shallow copy keeps the caller's value (reused for the deploy API call) untouched only for top-level scalar hashed fields; a nested field would need a deep copy. Note the constraint so it isn't silently broken later. Co-authored-by: Isaac
1 parent 58037af commit a3c6424

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

bundle/direct/dresources/state_compaction.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ func CompactState(cfg *ResourceLifecycleConfig, state any) (any, error) {
5656
return state, nil
5757
}
5858

59-
// Shallow copy so the caller's value (reused for the deploy) is untouched.
59+
// Shallow copy so the caller's value (reused for the deploy) is untouched. This is
60+
// safe only because every hashed_in_state field is a top-level scalar (e.g.
61+
// serialized_dashboard): SetByString overwrites it on the copy directly. A field
62+
// reached through a shared pointer/slice/map would need a deep copy here.
6063
out := reflect.New(rv.Type().Elem())
6164
out.Elem().Set(rv.Elem())
6265
compacted := out.Interface()

0 commit comments

Comments
 (0)