From 5c60076d7115cc7a1b0b4ac6a869525d14778f3d Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Mon, 29 Mar 2021 09:17:42 +0200 Subject: [PATCH] Ensure module is linked to record before wf is executed --- compose/service/record.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/compose/service/record.go b/compose/service/record.go index 7741e8a14..0ce388557 100644 --- a/compose/service/record.go +++ b/compose/service/record.go @@ -483,6 +483,9 @@ func (svc record) create(ctx context.Context, new *types.Record) (rec *types.Rec rve *types.RecordValueErrorSet ) + // ensure module ref is set before running through records workflows and scripts + new.SetModule(m) + if svc.optEmitEvents { if rve = svc.procCreate(ctx, svc.store, invokerID, m, new); !rve.IsValid() { return nil, RecordErrValueInput().Wrap(rve) @@ -514,6 +517,9 @@ func (svc record) create(ctx context.Context, new *types.Record) (rec *types.Rec return } + // ensure module ref is set before running through records workflows and scripts + new.SetModule(m) + // At this point we can return the value rec = new @@ -727,6 +733,10 @@ func (svc record) update(ctx context.Context, upd *types.Record) (rec *types.Rec rve *types.RecordValueErrorSet ) + // ensure module ref is set before running through records workflows and scripts + upd.SetModule(m) + old.SetModule(m) + if svc.optEmitEvents { // Handle input payload if rve = svc.procUpdate(ctx, svc.store, invokerID, m, upd, old); !rve.IsValid() { @@ -764,6 +774,10 @@ func (svc record) update(ctx context.Context, upd *types.Record) (rec *types.Rec return nil, err } + // ensure module ref is set before running through records workflows and scripts + upd.SetModule(m) + old.SetModule(m) + // Final value cleanup // These (clean) values are returned (and sent to after-update handler) upd.Values = upd.Values.GetClean() @@ -897,6 +911,9 @@ func (svc record) delete(ctx context.Context, namespaceID, moduleID, recordID ui return nil, RecordErrNotAllowedToDelete() } + // ensure module ref is set before running through records workflows and scripts + del.SetModule(m) + if svc.optEmitEvents { // Calling before-record-delete scripts if err = svc.eventbus.WaitFor(ctx, event.RecordBeforeDelete(nil, del, m, ns, nil)); err != nil { @@ -915,6 +932,9 @@ func (svc record) delete(ctx context.Context, namespaceID, moduleID, recordID ui return nil, err } + // ensure module ref is set before running through records workflows and scripts + del.SetModule(m) + if svc.optEmitEvents { _ = svc.eventbus.WaitFor(ctx, event.RecordAfterDeleteImmutable(nil, del, m, ns, nil)) }