Raathmd

Raathmd

Ash Framework Book - how to debug the actions

The step where previous_names are added is now preventing the save of an artist.
The artist table has the migrated field and the change function is in a separate module.
I see no messages in the terminal about why the save is not working.
How can i get some logging info from the submit action?
I added an inspect in the change function but nothing was output so i assume something is preventing it from executing this. I then added an input field for the previous_names field and started getting validation that it is required, even though allow_nil is true.

Any help appreciated.
Thanks

First Post!

zachdaniel

zachdaniel

Creator of Ash

:wave: I might need to see how what your code looks like up to this point to say for sure. I believe there is a step in the book that addresses that.

To answer your question more directly, there are a few things you can do to debug an action/form.

With the form

With a form that has been returned in the {:error, form} case of AshPhoenix.Form, you can do

AshPhoenix.Form.errors(form, for_path: :all) |> IO.inspect()

Not all errors are displayed in the form automatically because they may not tie to fields that are editable in the form itself. We also log a warning (IIRC that is the level) when we encounter an error that could not be displayed to the user due to not implementing the AshPhoenix.FormData.Error protocol (a safety measure to avoid displaying internal details to the user.

You can also peek at form.source (or form.source.source, if you have a %Phoenix.Form{}

in the action itself

change fn changeset, _ -> 
  Ash.Changeset.after_transaction(changeset, fn result -> 
    IO.inspect(result)
    result
  end)
end

You can add a hook like this to display the ok/error result from the action.

You’ll want to make sure that your action is not accepting previous_names as an input, and that your change is being run in all necessary places to set the attribute, that it has a default of [] etc.

Most Liked

sevenseacat

sevenseacat

Author of Ash Framework

Can do! I always forget to put that in everywhere :sweat_smile:

zachdaniel

zachdaniel

Creator of Ash

And this error


will be in the next release of ash

zachdaniel

zachdaniel

Creator of Ash

@ken-kost is correct about the def change/2 being the issue. This is an interesting one :sweat:

We have logic for an Ash.Resource.Change to automatically perform its atomic/3 callback if there is no change/3 callback defined. So when we try to do that, we find that there is no atomic/3 callback either, and that produces this error.

Something common to do with behaviours in Elixir (which Ash.Resource.Change is one), is to use @impl true or @impl BehaviourModule above each function that implements a callback of that behaviour. You can read more about that here: Typespecs reference — Elixir v1.18.3

If you had @impl true above def change(changeset, context), you would get a warning about that not being an actual callback available.

I think there are two things that we can do on our end to improve this:

@sevenseacat we can make sure to use @impl true in all of our examples of change/validation/calculation callback functions.

And for myself, I can add a check that at least one of change/3, atomic/3 or batch_change/3 is defined, as that is the minimum required for a change to function. That check also would have surfaced this issue :slight_smile:

Last Post!

ghannam80

ghannam80

Thanks @zachdaniel ,

The audit refers to monitor some critical resources changes “usually configuration resources” so that we can go to some UI to identify old value/new value and who did the change right from the start.

The sensitive data refers to those encrypted fields or in payment domain something like clear card number could be viewed only by users who have the privileges to do so while others could see a hashed or encrypted value.

I took a look at ash_state_ma chine and it seems serving the logic for changing the resources values utilizing maker/checker but looking for a sample repository or project to check it further.
btw , when will have the last chapter of the book?

Where Next?

Popular in Questions Top

ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 131117 1222
New
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement