Skip to content

Commit b68946a

Browse files
committed
[common] Fix override with empty value issue
OCTRL-916
1 parent d5fbf3e commit b68946a

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

common/gera/map.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -247,21 +247,21 @@ func (w *WrapMap[K, V]) Flattened() (map[K]V, error) {
247247
w.mu.RLock()
248248
defer w.mu.RUnlock()
249249

250-
out := make(map[K]V)
250+
thisMapCopy := make(map[K]V)
251251
for k, v := range w.theMap {
252-
out[k] = v
252+
thisMapCopy[k] = v
253253
}
254254
if w.parent == nil {
255-
return out, nil
255+
return thisMapCopy, nil
256256
}
257257

258258
flattenedParent, err := w.parent.Flattened()
259259
if err != nil {
260-
return out, err
260+
return thisMapCopy, err
261261
}
262262

263-
err = mergo.Merge(&out, flattenedParent)
264-
return out, err
263+
err = mergo.Merge(&flattenedParent, thisMapCopy, mergo.WithOverride)
264+
return flattenedParent, err
265265
}
266266

267267
func (w *WrapMap[K, V]) FlattenedParent() (map[K]V, error) {
@@ -283,24 +283,24 @@ func (w *WrapMap[K, V]) WrappedAndFlattened(m Map[K, V]) (map[K]V, error) {
283283

284284
w.mu.RLock()
285285

286-
out := make(map[K]V)
286+
thisMapCopy := make(map[K]V)
287287
for k, v := range w.theMap {
288-
out[k] = v
288+
thisMapCopy[k] = v
289289
}
290290

291291
w.mu.RUnlock()
292292

293293
if m == nil {
294-
return out, nil
294+
return thisMapCopy, nil
295295
}
296296

297297
flattenedM, err := m.Flattened()
298298
if err != nil {
299-
return out, err
299+
return thisMapCopy, err
300300
}
301301

302-
err = mergo.Merge(&out, flattenedM)
303-
return out, err
302+
err = mergo.Merge(&flattenedM, thisMapCopy, mergo.WithOverride)
303+
return flattenedM, err
304304
}
305305

306306
func (w *WrapMap[K, V]) Raw() map[K]V { // allows unmutexed access to map, can be unsafe!

0 commit comments

Comments
 (0)