No actor in after_action context
I wondering what is the correct or recommended way of passing the actor down to a
after_change
callback. I've tried to use the context
but the actor
was always nil
. I've ended up doing this:
But I'm not sure if I'm doing it properly and I'm missing something here?5 Replies
actor should be in the third argument of the after_action callback, which you are discarding as
_context
I tried that before, but I was always getting
actor: nil
from it.
the test was assert {:ok, model} = Model |> Ash.Changeset.for_create(:create, attrs) |> Ash.create(actor: user)
and it works if I get it from changeset.context
but clearly that :private
there doesn't feel right 😛Pass the actor option when building the changeset
If you don't it won't be available in the context
Thanks @Zach!!! That fixed the issue. Later I also found it some reference in the docs . Wondering if either removing the
Ash.<action>(actor: ...)
configuration or finding a way to bypass it to the incoming changeset would be possible. IMO the current configuration makes a bit obscure because it may not work depending on how the underlaying action was configured.We can possibly warn or raise if a different, non-nil actor is passed there than what was originally provided.