Hi all,
I am getting a strange behaviour where Ash.update is not passing the context’s actor down the change after_action(&ProcessApproved.run/3)
, but when I call the same action through the code interface it works.
What could I be doing wrong?
This doesn’t work
context = %{actor: user, tenant: user.current_tenant, authorize?: false}
step
|> Ash.Changeset.for_update(:approve, %{actor_remarks: "Test Remarks"})
|> Ash.Changeset.set_context(context)
|> Ash.update()
But this works
context = [actor: actor, tenant: actor.current_tenant, authorize?: false]
Approvals.approve_step!(step, %{actor_remarks: remarks}, context)
Resource Action definition
update :approve do
accept [:actor_remarks]
require_atomic? false
filter expr(status == :pending)
change set_attribute(:status, :approved)
change after_action(&ProcessApproved.run/3)
end
after action fun definition
defmodule ProcessApproved do
def run(_changeset, step, context) do
dbg(context)
{:ok, step}
end
Output of the dbg(context)
context #=> %Ash.Resource.Change.Context{
actor: nil,
tenant: "tenant_name",
authorize?: true,
tracer: nil,
bulk?: false
}