no data in Ash.DataLayer.Simple

I have this action in one of my resources
read :read do
argument :ref, :string do
allow_nil? false
end

get? true

prepare fn query, _ ->
Ash.Query.before_action(query, fn query ->
case Api.quote(%Input{
option_ref_id: query.arguments.ref
}) do
{:ok, response} ->
data =
response
|> Map.get(:body)
|> get_in(["data", "hotelX", "quote", "optionQuote"])
|> JdlEngine.Util.Json.json_to_elixir()
|> Map.put(:id, query.arguments.ref)
|> IO.inspect(label: :data)

query = Ash.DataLayer.Simple.set_data(query, [data])

IO.inspect(Map.from_struct(query))

query

error ->
error
end
end)
end
end
read :read do
argument :ref, :string do
allow_nil? false
end

get? true

prepare fn query, _ ->
Ash.Query.before_action(query, fn query ->
case Api.quote(%Input{
option_ref_id: query.arguments.ref
}) do
{:ok, response} ->
data =
response
|> Map.get(:body)
|> get_in(["data", "hotelX", "quote", "optionQuote"])
|> JdlEngine.Util.Json.json_to_elixir()
|> Map.put(:id, query.arguments.ref)
|> IO.inspect(label: :data)

query = Ash.DataLayer.Simple.set_data(query, [data])

IO.inspect(Map.from_struct(query))

query

error ->
error
end
end)
end
end
I can see that ASh.DataLayer.Simple.set_data is called with the correct value, but I always get a %Ash.Error.SimpleDataLayer.NoDataProvidederror back. Not sure what I'm doing wrong Thanks in advance
9 Replies
ZachDaniel
ZachDaniel3y ago
Hm…that looks right to me. For testing, could you take it out of the before_action hook?
barnabasj
barnabasjOP3y ago
That works, thank you
barnabasj
barnabasjOP3y ago
Maybe you could update your post here https://discordapp.com/channels/711271361523351632/1071863822844952606/1071866406414602341, as I copied it from there. So the next person doesn't have the same problem
Discord
Discord - A New Way to Chat with Friends & Communities
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
ZachDaniel
ZachDaniel3y ago
well, you shouldn't have to do that and in fact I'd suggest not doing that so if it only works without the before_action then that is a bug can you try main with the before_action hook?
barnabasj
barnabasjOP3y ago
main didn't fix it for me
ZachDaniel
ZachDaniel3y ago
damn
barnabasj
barnabasjOP3y ago
still getting a Ash.Error.SimpleDataLayer.NoDataProvided error
ZachDaniel
ZachDaniel3y ago
okay try again 😄
barnabasj
barnabasjOP3y ago
That did the trick, thank you

Did you find this page helpful?