Ensure field values are processed after any default values are set

This commit is contained in:
Tobie Morgan Hitchcock 2021-04-17 15:01:31 +01:00
parent d476bec5a2
commit e9849a5a39

View file

@ -322,16 +322,6 @@ func (d *document) mrgFld(ctx context.Context, met method) (err error) {
val = conv.MustBe(fd.Type, val) val = conv.MustBe(fd.Type, val)
// Ensure the field is the correct type
if val != nil {
if now, err := conv.ConvertTo(fd.Type, fd.Kind, val); err != nil {
val = nil
} else {
val = now
}
}
// We are setting the value of the field // We are setting the value of the field
if fd.Value != nil && d.i.e.opts.fields { if fd.Value != nil && d.i.e.opts.fields {
@ -352,6 +342,16 @@ func (d *document) mrgFld(ctx context.Context, met method) (err error) {
} }
// Ensure the field is the correct type
if val != nil {
if now, err := conv.ConvertTo(fd.Type, fd.Kind, val); err != nil {
val = nil
} else {
val = now
}
}
// We are checking the value of the field // We are checking the value of the field
if fd.Assert != nil && d.i.e.opts.fields { if fd.Assert != nil && d.i.e.opts.fields {