martosaur
Can't fan out workflows with cascade functions if they have a context
Here’s an example workflow that has a container sub-workflow that fans out multiple sub-workflows each of which contains a cascade function (pls don’t judge me)
defmodule Single do
alias Oban.Pro.Workflow
def workflow() do
Workflow.new()
|> Workflow.put_context(%{hello: "world"})
|> Workflow.add_cascade(:foo, &cascade/1)
end
def cascade(_context) do
IO.inspect("Single fan-out cascade complete")
end
end
defmodule Mothership do
alias Oban.Pro.Workflow
def workflow() do
fan_out_wf =
Enum.reduce(1..2, Workflow.new(), fn i, wf ->
Workflow.add_workflow(wf, to_string(i), Single.workflow())
end)
Workflow.new()
|> Workflow.add_workflow(:fan_out, fan_out_wf)
end
end
When I run it:
Mothership.workflow() |> Oban.insert_all()
Jobs fail with this error:
** (Ecto.MultipleResultsError) expected at most one result but got 2 in query:
from j0 in Oban.Job,
where: j0.state in [
"scheduled",
"available",
"executing",
"retryable",
"completed",
"discarded",
"cancelled"
],
where: fragment(
"? ? 'workflow_id' AND ?->>'workflow_id' = ?",
j0.meta,
j0.meta,
^"019b1e4a-fb19-76d5-b41c-b4e83d2e79e0"
),
where: j0.meta["name"] in ^["context"],
order_by: [asc: j0.id],
select: j0.meta
(ecto 3.13.5) lib/ecto/repo/queryable.ex:166: Ecto.Repo.Queryable.one/3
(oban_pro 1.6.9) lib/oban/pro/workflow.ex:2228: Oban.Pro.Workflow.get_recorded/3
(oban_pro 1.6.9) lib/oban/pro/workflow/cascade.ex:39: Oban.Pro.Workflow.Cascade.all_context/2
(oban_pro 1.6.9) lib/oban/pro/workflow/cascade.ex:23: Oban.Pro.Workflow.Cascade.process/1
(oban_pro 1.6.9) lib/oban/pro/worker.ex:1156: Oban.Pro.Worker.process/3
(oban 2.20.2) lib/oban/queue/executor.ex:143: Oban.Queue.Executor.perform/1
(oban 2.20.2) lib/oban/queue/executor.ex:75: Oban.Queue.Executor.call/1
(elixir 1.19.3) lib/task/supervised.ex:105: Task.Supervised.invoke_mfa/2
(elixir 1.19.3) lib/task/supervised.ex:40: Task.Supervised.reply/4
Without put_context it’s working fine. Seems like a bug?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated!
To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead.
Sta...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First 10 of 15 Posts
martosaur
Hmm I also run into the same error while trying to come up with a workaround using normal jobs, not cascade functions. The whole workflow composition must be problematic. Am I using it wrong?
sorentwo
It’s likely that we can put in a fix to prevent the error, but based on the example, you’re using it slightly wrong. There’s no need to add a workflow to a workflow without any other jobs in it, just return the workflow:
Fewer nested workflows are better when possible. We’ll work on a fix for the query issue regardless.
martosaur
Thanks! I purposefully removed from the example as much as possible. The full version contains more stages, and looks more like this:
The reason I wrap fan-out in a workflow is so that I could depend on the fan-out without explicitly collecting every fan out job id at workflow creation time, if this makes sense!
alexbiehl
I am seeing the same thing with Oban Pro v1.6.9. Is the workaround to avoid a second Workflow.put_context and use traditional Workers to get the values into my jobs?
jpress
This would appear to be a pretty big issue preventing the composition of workflows. The way I see it, this prevents sub-workflows added via
add_workfloworadd_graftfrom being able to set context data received from the parent workflow on themselves.Maybe I am misunderstanding how relevant data should be shared between workflows. Is there another, more canonical/idiomatic way? If not, is there an estimated timeline for a fix? At the moment, this is a blocker for my work.
sorentwo
We’re working on a fix currently and hope to have something ready in the next day or so. If not, I’ll suggest an alternative way to handle this.
martosaur
Just checked this against 1.6.10 and this seems to be fixed
alexbiehl
The original issue seems to be fixed. But I think it’s not over yet.
It looks like there’s an issue with the how the context is being shared with sub workflows.
Here’s a reproducer that Claude extracted from our use case that documents and demonstrates the issue:
Reproducer
sorentwo
@alexbiehl Thanks for the reproduction, that helped. It wasn’t over yet! Fixed for the next patch.
alexbiehl
Awesome. Looking forward to give it a try.
That being said, I saw
in the v1.6.11 — 2026-01-19 release.
I tested with the reproducer and it still fails to work. I guess the changelog is pointing to the original issue?