Reset ctx variables between calculating field VALUE and ASSERT
If the field value was changed in the VALUE statement, then the context variables were not reset to reflect this change in the ASSERT statement. As a result the ASSERT would receive the old values prior to being affected by the VALUE statement.
This commit is contained in:
parent
14d3539dbf
commit
7733b7b129
1 changed files with 11 additions and 1 deletions
12
db/merge.go
12
db/merge.go
|
@ -271,6 +271,8 @@ func (d *document) mrgFld(ctx context.Context) (err error) {
|
||||||
|
|
||||||
err = d.current.Walk(func(key string, val interface{}) (err error) {
|
err = d.current.Walk(func(key string, val interface{}) (err error) {
|
||||||
|
|
||||||
|
vars := data.New()
|
||||||
|
|
||||||
var old = d.initial.Get(key).Data()
|
var old = d.initial.Get(key).Data()
|
||||||
|
|
||||||
// Ensure the field is the correct type
|
// Ensure the field is the correct type
|
||||||
|
@ -281,7 +283,8 @@ func (d *document) mrgFld(ctx context.Context) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vars := data.New()
|
// Reset the variables
|
||||||
|
|
||||||
vars.Set(val, varKeyValue)
|
vars.Set(val, varKeyValue)
|
||||||
vars.Set(val, varKeyAfter)
|
vars.Set(val, varKeyAfter)
|
||||||
vars.Set(old, varKeyBefore)
|
vars.Set(old, varKeyBefore)
|
||||||
|
@ -295,6 +298,13 @@ func (d *document) mrgFld(ctx context.Context) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset the variables
|
||||||
|
|
||||||
|
vars.Set(val, varKeyValue)
|
||||||
|
vars.Set(val, varKeyAfter)
|
||||||
|
vars.Set(old, varKeyBefore)
|
||||||
|
ctx = context.WithValue(ctx, ctxKeySubs, vars)
|
||||||
|
|
||||||
// We are checking the value of the field
|
// We are checking the value of the field
|
||||||
|
|
||||||
if fd.Assert != nil {
|
if fd.Assert != nil {
|
||||||
|
|
Loading…
Reference in a new issue