thawke

thawke

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

Showing Posts 1 to 4

ken-kost

ken-kost

It’s related to Ash.Type.dump_to_embedded/3 call.
I was able to make this work:

iex(12)> d = DateTime.utc_now() |> DateTime.truncate(:second)
~U[2025-07-15 16:48:07Z]
iex(13)> Ash.Type.dump_to_embedded :utc_datetime_usec, d
{:ok, ~U[2025-07-15 16:48:07Z]}

:thinking: The docs say for dump_to_embedded:

  @doc """
  Casts a value from the Elixir type to a value that can be embedded in another data structure.

  Embedded resources expect to be stored in JSON, so this allows things like UUIDs to be stored
  as strings in embedded resources instead of binary.
  """

So not sure if this is even right. Should it be a string after the dump? :person_shrugging:

zachdaniel

zachdaniel

Creator of Ash

@thawke please open an issue on ash_events @Torkan is working on this area currently. In fact it may already be fixed in main, would be worth checking.

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?

thawke

thawke OP

Can confirm this works in the main branch. Thanks!

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews