escargot33

escargot33

AshEvents: No such input `id` for action; How to handle auto-generated primary keys?

I am currently trying to enable event tracking for one of my resources. As such, it contains the following event DSL:

defmodule MyApp.MyResource do
  events do
    event_log MyApp.MyEventLog
  end
  attributes do
    uuid_primary_key :id
    attribute :field1, ...
    attribute :field2, ...
  end
  actions do
    create :create do
      accept [:field1, :field2]
      argument :xyz, ...
    end
  end
end

The event tracking works correctly and I can see the events being populated in my event log with both data and changed_attributes being set correctly for each call of the :create action. The auto-generated UUID is recorded in changed_attributes as expected.

When I then try to replay the events as follows:
MyApp.MyEventLog |> Ash.ActionInput.for_action(:replay, %{}) |> Ash.run_action!()

I get this error:

** (Ash.Error.Invalid) 
Bread Crumbs:
  > Error returned from: MyApp.MyResource.create

Invalid Error

* No such input `id` for action MyApp.MyResource.create

The attribute exists on MyApp.MyResource, but is not accepted by MyApp.MyResource.create


The attribute is currently `writable?: false`, which means that it can never be accepted by an action.

Valid Inputs:

* :field1
* :field2
* ...

This left me very confused and unsure of how to proceed. The AshEvents documentation explicitly says that auto-genered UUIDs are recorded, and I can see that they are. As far as I understand, the default :force_change strategy for all actions shouldn’t require the field to be listed in accept. Furthermore, the examples on the Alembic blog also use resources with auto-generated UUIDs and do not explicitly accept id.

What changes do I have to make in order to get replay working?

Most Liked

Torkan

Torkan

Hi, AshEvents maintainer here!

I will start working on a fix for this :smiley:

As a temporary measure in the meantime, try making these changes:

  1. uuid_primary_key :id, writable?: true
  2. Add :id to the action’s accept list

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
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