thawke

thawke

Ash Events - Datetime Won't Save

I’m attempting to create a resource that has a :datetime attribute:

attribute :pickup_time, :datetime do
  public? true
  allow_nil? false
end

The resource is setup with AshEvents and is set to log the events with the following code:

events do
    event_log(Api.Events.Event)
end

If I post to the creation endpoint with invalid data, like an integer for example, I get the expected error:

{
  "errors": [
    {
      "code": "invalid_attribute",
      "id": "6a24f1be-5c2c-497d-b860-246d8f7d0ecf",
      "meta": {},
      "status": "400",
      "title": "InvalidAttribute",
      "source": {
        "pointer": "/data/attributes/pickup_time"
      },
      "detail": "Could not cast input to datetime"
    }
  ],
  "jsonapi": {
    "version": "1.0"
  }
}

However if I send "pickup_time": "2025-07-15" or "pickup_time": "2025-07-15 00:00:00" then it seems to pass validation but (ash_events 0.4.2) lib/events/action_wrapper_helpers.ex:23 appears to throw a match error. (Value returned from dump_to_embedded is :error)

Full stack trace:

[error] ** (Ash.Error.Unknown) 
Bread Crumbs:
  > Exception raised in: Api.Shipments.Shipment.create

Unknown Error

* ** (MatchError) no match of right hand side value: :error
  (ash_events 0.4.2) lib/events/action_wrapper_helpers.ex:23: AshEvents.Events.ActionWrapperHelpers.dump_value/2
  (ash_events 0.4.2) lib/events/action_wrapper_helpers.ex:54: anonymous fn/2 in AshEvents.Events.ActionWrapperHelpers.create_event!/4
  (elixir 1.18.4) lib/enum.ex:1722: anonymous fn/3 in Enum.map/2
  (stdlib 6.2.2.1) maps.erl:860: :maps.fold_1/4
  (elixir 1.18.4) lib/enum.ex:2558: Enum.map/2
  (ash_events 0.4.2) lib/events/action_wrapper_helpers.ex:47: AshEvents.Events.ActionWrapperHelpers.create_event!/4
  (ash_events 0.4.2) lib/events/create_action_wrapper.ex:19: AshEvents.CreateActionWrapper.create/3
  (ash 3.5.26) lib/ash/actions/create/create.ex:309: anonymous fn/6 in Ash.Actions.Create.commit/3
  (ash 3.5.26) lib/ash/changeset/changeset.ex:4645: Ash.Changeset.run_around_actions/2
  (ash 3.5.26) lib/ash/changeset/changeset.ex:4181: anonymous fn/3 in Ash.Changeset.with_hooks/3
  (api 0.1.0) lib/api/repo.ex:2: anonymous fn/1 in Api.Repo."transaction (overridable 1)"/2
  (ecto 3.13.2) lib/ecto/repo/transaction.ex:7: anonymous fn/2 in Ecto.Repo.Transaction.transact/4
  (ecto_sql 3.13.2) lib/ecto/adapters/sql.ex:1458: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
  (db_connection 2.8.0) lib/db_connection.ex:1753: DBConnection.run_transaction/4
  (ash 3.5.26) lib/ash/changeset/changeset.ex:4179: anonymous fn/3 in Ash.Changeset.with_hooks/3
  (ash 3.5.26) lib/ash/changeset/changeset.ex:4323: anonymous fn/2 in Ash.Changeset.transaction_hooks/2
  (ash 3.5.26) lib/ash/changeset/changeset.ex:4166: Ash.Changeset.with_hooks/3
  (ash 3.5.26) lib/ash/actions/create/create.ex:261: Ash.Actions.Create.commit/3
  (ash 3.5.26) lib/ash/actions/create/create.ex:132: Ash.Actions.Create.do_run/4
  (ash 3.5.26) lib/ash/actions/create/create.ex:50: Ash.Actions.Create.run/4
    (ash_events 0.4.2) lib/events/action_wrapper_helpers.ex:23: AshEvents.Events.ActionWrapperHelpers.dump_value/2
    (ash_events 0.4.2) lib/events/action_wrapper_helpers.ex:54: anonymous fn/2 in AshEvents.Events.ActionWrapperHelpers.create_event!/4
    (elixir 1.18.4) lib/enum.ex:1722: anonymous fn/3 in Enum.map/2
    (stdlib 6.2.2.1) maps.erl:860: :maps.fold_1/4
    (elixir 1.18.4) lib/enum.ex:2558: Enum.map/2
    (ash_events 0.4.2) lib/events/action_wrapper_helpers.ex:47: AshEvents.Events.ActionWrapperHelpers.create_event!/4
    (ash_events 0.4.2) lib/events/create_action_wrapper.ex:19: AshEvents.CreateActionWrapper.create/3
    (ash 3.5.26) lib/ash/actions/create/create.ex:309: anonymous fn/6 in Ash.Actions.Create.commit/3
    (ash 3.5.26) lib/ash/changeset/changeset.ex:4645: Ash.Changeset.run_around_actions/2
    (ash 3.5.26) lib/ash/changeset/changeset.ex:4181: anonymous fn/3 in Ash.Changeset.with_hooks/3
    (api 0.1.0) lib/api/repo.ex:2: anonymous fn/1 in Api.Repo."transaction (overridable 1)"/2
    (ecto 3.13.2) lib/ecto/repo/transaction.ex:7: anonymous fn/2 in Ecto.Repo.Transaction.transact/4
    (ecto_sql 3.13.2) lib/ecto/adapters/sql.ex:1458: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
    (db_connection 2.8.0) lib/db_connection.ex:1753: DBConnection.run_transaction/4
    (ash 3.5.26) lib/ash/changeset/changeset.ex:4179: anonymous fn/3 in Ash.Changeset.with_hooks/3
    (ash 3.5.26) lib/ash/changeset/changeset.ex:4323: anonymous fn/2 in Ash.Changeset.transaction_hooks/2
    (ash 3.5.26) lib/ash/changeset/changeset.ex:4166: Ash.Changeset.with_hooks/3
    (ash 3.5.26) lib/ash/actions/create/create.ex:261: Ash.Actions.Create.commit/3
    (ash 3.5.26) lib/ash/actions/create/create.ex:132: Ash.Actions.Create.do_run/4
    (ash 3.5.26) lib/ash/actions/create/create.ex:50: Ash.Actions.Create.run/4

I created a small reproduction repo: https://github.com/thenhawke/ash_events_reporoduction

Marked As Solved

Torkan

Torkan

Hi @thawke!

Like @zachdaniel suggested, this issue should already be resolved in main.

Can you try using the main branch instead of the latest published version, and see if that works?

Last Post!

thawke

thawke

Can confirm this works in the main branch. Thanks!

Where Next?

Popular in Questions Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49084 226
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
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

We're in Beta

About us Mission Statement