Skip to content

Commit 0e4e7ec

Browse files
authored
datastore: fix WithIgnoreFieldMismatch for nested slices (#13799)
Fixes: #10822 This change ensures that propertyLoader.load continues iterating through slice elements even if individual elements encounter loading errors (like ErrFieldMismatch). Previously, when loading a slice of structs, if one element caused an error (e.g. valid field mismatch), the loader would abort immediately. This prevented subsequent elements from being loaded, even if the user intended to ignore these mismatches using WithIgnoreFieldMismatch. The fix captures the first error encountered but continues the loop to ensure all valid data is loaded. The error is returned at the end, preserving the existing error reporting behavior (which WithIgnoreFieldMismatch relies on).
1 parent 892c5d3 commit 0e4e7ec

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

datastore/load.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,16 @@ func (l *propertyLoader) load(codec fields.List, structValue reflect.Value, p Pr
7878
if !ok {
7979
return l.loadOneElement(codec, structValue, p, prev)
8080
}
81+
var firstErr string
8182
for _, val := range sl {
8283
p.Value = val
8384
if errStr := l.loadOneElement(codec, structValue, p, prev); errStr != "" {
84-
return errStr
85+
if firstErr == "" {
86+
firstErr = errStr
87+
}
8588
}
8689
}
87-
return ""
90+
return firstErr
8891
}
8992

9093
// loadOneElement loads the value of Property p into structValue based on the provided

0 commit comments

Comments
 (0)