From 7733b7b1290792d1889fd4ca59a252fd625d1e8b Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 4 Dec 2017 10:09:49 +0000 Subject: [PATCH] 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. --- db/merge.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/db/merge.go b/db/merge.go index 1a01d84d..4fede17b 100644 --- a/db/merge.go +++ b/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) { + vars := data.New() + var old = d.initial.Get(key).Data() // 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, varKeyAfter) 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 if fd.Assert != nil {