A cascaded sub- sub-workflow does not receive its deps

I have a workflow using cascades, which looks more or less like this:

def insert(ctx) do
  Workflow.new()
  |> Workflow.put_context(ctx)
  .
  .
  |> Workflow.add_cascade(:research, &research/1, deps: ...)
  |> Workflow.add_graft(:search, &search/1, deps: :research)
  .
  .
  |> Oban.insert_all()
end

def search(ctx) do
  Workflow.new()
  |> Workflow.put_context(ctx)
  |> Workflow.add_cascade(:results, &run_search/1)
  |> Workflow.add_graft(:reviewed, &review_results/1, deps: :results)
  |> Workflow.add_cascade(:reviewed_results, &collect_results/1, deps: :reviewed)
  |> Workflow.apply_graft()
  |> Oban.insert_all()
end

def run_search(%{research: research}) do
  ...
end

def review_results(%{results: results}) do
  ...
end

That is, the initial workflow does some work and builds context, then a graft is added in to perform a search. This graft adds a sub-workflow which itself includes grafts - the intention is that the results are fanned out for review in parallel, then collected and returned to the parent workflow. That will then add further grafts if necessary to repeat the search until we have what we need.

The issue I’m having is that in the :search sub-workflow, the :reviewed graft specifies deps: :results but review_results/1 receives only ctx and :results is not present.

Am I holding it wrong?

1 Like

No, you weren’t holding it wrong. There was a bug in how the context was constructed for nested grafts. In your example, the results would be contained within a nested search map. We’ve fixed the issue on main and will have it out in a v1.6.8 patch soon.

3 Likes