From e9849a5a39fd5ebd53beae21292d7f5bc100ae99 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sat, 17 Apr 2021 15:01:31 +0100 Subject: [PATCH] Ensure field values are processed after any default values are set --- db/merge.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/db/merge.go b/db/merge.go index c6517e8c..66824f4f 100644 --- a/db/merge.go +++ b/db/merge.go @@ -322,16 +322,6 @@ func (d *document) mrgFld(ctx context.Context, met method) (err error) { 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 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 if fd.Assert != nil && d.i.e.opts.fields {