Don’t assert the value of a field type
Previously if a field had a type, and a value was entered which did not match that type, then an error was raised, even though the ASSERT clause was not set. Now the field will be set to nil if the field does not match the specified type, and the ASSERT clause can be used to ensure that a valid value is always entered.
This commit is contained in:
parent
2249086887
commit
b4dfaf2898
1 changed files with 9 additions and 5 deletions
14
db/merge.go
14
db/merge.go
|
@ -290,7 +290,7 @@ func (d *document) mrgFld(ctx context.Context) (err error) {
|
|||
|
||||
for _, fd := range fds {
|
||||
|
||||
err = d.current.Walk(func(key string, val interface{}) (err error) {
|
||||
err = d.current.Walk(func(key string, val interface{}) error {
|
||||
|
||||
vars := data.New()
|
||||
|
||||
|
@ -299,8 +299,10 @@ func (d *document) mrgFld(ctx context.Context) (err error) {
|
|||
// Ensure the field is the correct type
|
||||
|
||||
if val != nil {
|
||||
if val, err = conv.ConvertTo(fd.Type, fd.Kind, val); err != nil {
|
||||
val = old
|
||||
if now, err := conv.ConvertTo(fd.Type, fd.Kind, val); err != nil {
|
||||
val = nil
|
||||
} else {
|
||||
val = now
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -314,8 +316,10 @@ func (d *document) mrgFld(ctx context.Context) (err error) {
|
|||
// We are setting the value of the field
|
||||
|
||||
if fd.Value != nil {
|
||||
if val, err = d.i.e.fetch(ctx, fd.Value, d.current); err != nil {
|
||||
if now, err := d.i.e.fetch(ctx, fd.Value, d.current); err != nil {
|
||||
return err
|
||||
} else {
|
||||
val = now
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -343,7 +347,7 @@ func (d *document) mrgFld(ctx context.Context) (err error) {
|
|||
d.current.Del(key)
|
||||
}
|
||||
|
||||
return
|
||||
return nil
|
||||
|
||||
}, fd.Name.ID)
|
||||
|
||||
|
|
Loading…
Reference in a new issue