Generic action has `api` nil in context when called from `code_interface`

I have a generic action in my resource:
action :blibs, :any do
run fn _, context ->
__MODULE__
|> Ash.Query.filter(...)
context.api.read()
end
end
action :blibs, :any do
run fn _, context ->
__MODULE__
|> Ash.Query.filter(...)
context.api.read()
end
end
and I have it set in that resource code_interface:
code_interface do
define_for FeedbackCupcake.Accounts

define :blibs
end
code_interface do
define_for FeedbackCupcake.Accounts

define :blibs
end
Since I have the define_for in the code_interface I was expecting that the generic action context will have the api key filled with FeedbackCupcake.Accounts so I can fetch it and use in to call read function. Is this a bug? If not, how can I figure out what is the API I should call that function in this case?
4 Replies
ZachDaniel
ZachDaniel2y ago
Hmm…I’d have to look. Does it have the api in the context when you call it outside of the code interface? Might just be a missing feature 🙂 And one that shouldn’t be too difficult to add
Blibs
BlibsOP2y ago
I will check that ASAP and return with an update I belive that is the correct way to run a generic action right?
FeedbackCupcake.Accounts.User |> Ash.ActionInput.for_action(:blibs, %{}) |> FeedbackCupcake.Accounts.run_action()
FeedbackCupcake.Accounts.User |> Ash.ActionInput.for_action(:blibs, %{}) |> FeedbackCupcake.Accounts.run_action()
If so, the api field in the context is still nil
ZachDaniel
ZachDaniel2y ago
Gotcha. I think what we should do is add an api field to ActionInput And set that field when you call run_action Should be a pretty small change. You want to take a stab at it?
Blibs
BlibsOP2y ago
Sure, I will try it out today in the evening Hey @Zach Daniel , took me some time to go back to this, but FYI I just created a small PR which fills the api field from ActionInput when running an action. https://github.com/ash-project/ash/pull/676

Did you find this page helpful?