Ash FrameworkAF
Ash Framework2w ago
4 replies
tme_317

Numericality validation breaking album update in Ash Framework Book

I'm working through the excellent Ash Framework book (thanks!) on fully updated Ash (i.e. 3.11.3), Elixir 1.19.4, Erlang 28.3 and once I added:
    validate numericality(:year_released, greater_than: 1920, less_than_or_equal_to: &__MODULE__.next_year/0),
      where: [present(:year_released)],
      message: "Must be between 1920 and next year"

and def next_year(), do: Date.utc_today().year + 1
I am now getting an exception when attempting to save an album update. Abridged stacktrace:
[debug] HANDLE EVENT "save" in TunezWeb.Albums.FormLive
  Parameters: %{"form" => %{"cover_image_url" => "", "name" => "In Through the Out Door", "year_released" => "1980"}}
[error] GenServer #PID<0.3218.0> terminating
** (Ash.Error.Unknown)
Bread Crumbs:
  > Exception raised in: Tunez.Music.Album.update

Unknown Error

* ** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not an atom

  :erlang.function_exported({[AshPostgres.Timestamptz, AshPostgres.Timestamptz], Ash.Type.Boolean}, :evaluate_operator, 1)
  (ash 3.11.3) lib/ash/query/operator/operator.ex:89: anonymous fn/4 in Ash.Query.Operator.do_evaluate/1
  (elixir 1.19.4) lib/enum.ex:1210: anonymous fn/3 in Enum.find_value/3

When I comment out this new validation everything works again. Also the match validation on cover_image_url seems to be working great so only the numericality is breaking.
Was this page helpful?