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 functions) should such a module then check the existence and validity of the arguments again?
Example:
# in the resource
defmodule MyResource do
actions do
update :do_something do
argument :foobar, :string, allow_nil?: false
change NaiveCustomChange # or the other one, whatever
end
end
end
defmodule NaiveCustomChange do
use Ash.Resource.Change
@impl true
def change(changeset, opts, _context) do
foobar_from_args = Ash.Changeset.get_argument(changeset, :foobar)
Ash.Changeset.change_attribute(changeset, :foobar, foobar_from_args)
end
end
vs
defmodule PessimisticCustomChange do
use Ash.Resource.Change
@impl true
def change(changeset, opts, _context) do
case Ash.Changeset.get_argument(changeset, :foobar) do
foobar when is_binary(foobar) ->
Ash.Changeset.change_attribute(changeset, :foobar, foobar)
_ ->
Ash.Changeset.add_error(changeset,
field: :foobar,
message: "needs the argument :foobar"
)
end
end
end
Does anybody have any reason to prefer one over the other?






















