diff --git a/lib/ash/actions/destroy/destroy.ex b/lib/ash/actions/destroy/destroy.ex index 45d604f54..c7fcc9f19 100644 --- a/lib/ash/actions/destroy/destroy.ex +++ b/lib/ash/actions/destroy/destroy.ex @@ -98,6 +98,8 @@ defmodule Ash.Actions.Destroy do with %{valid?: true} = changeset <- Ash.Changeset.validate_multitenancy(changeset), %{valid?: true} = changeset <- changeset(changeset, domain, action, opts), %{valid?: true} = changeset <- authorize(changeset, opts), + %{valid?: true} = changeset <- + Ash.Changeset.add_atomic_validations(changeset, opts[:actor], []), {:ok, result, instructions} <- commit(changeset, domain, opts) do changeset.resource |> add_notifications( diff --git a/lib/ash/actions/update/bulk.ex b/lib/ash/actions/update/bulk.ex index 8787dfd7e..1947b941b 100644 --- a/lib/ash/actions/update/bulk.ex +++ b/lib/ash/actions/update/bulk.ex @@ -497,7 +497,6 @@ defmodule Ash.Actions.Update.Bulk do authorize_atomic_changeset(query, atomic_changeset, opts), {query, atomic_changeset} <- add_changeset_filters(query, atomic_changeset), - atomic_changeset <- Ash.Changeset.move_attributes_to_atomics(atomic_changeset), %Ash.Changeset{valid?: true} = atomic_changeset <- Ash.Changeset.handle_allow_nil_atomics(atomic_changeset, opts[:actor]), atomic_changeset <- sort_atomic_changes(atomic_changeset), diff --git a/lib/ash/changeset/changeset.ex b/lib/ash/changeset/changeset.ex index 2085ae58f..82e26682a 100644 --- a/lib/ash/changeset/changeset.ex +++ b/lib/ash/changeset/changeset.ex @@ -947,21 +947,16 @@ defmodule Ash.Changeset do {:cont, %{changeset | arguments: Map.put(changeset.arguments, key, value)}} attribute = Ash.Resource.Info.attribute(changeset.resource, key) -> - if Ash.Expr.expr?(value) do - case Ash.Type.cast_atomic(attribute.type, value, attribute.constraints) do - {:atomic, atomic} -> - atomic = set_error_field(atomic, attribute.name) - {:cont, atomic_update(changeset, attribute.name, {:atomic, atomic})} + case Ash.Type.cast_atomic(attribute.type, value, attribute.constraints) do + {:atomic, atomic} -> + atomic = set_error_field(atomic, attribute.name) + {:cont, atomic_update(changeset, attribute.name, {:atomic, atomic})} - {:error, error} -> - {:cont, add_invalid_errors(value, :attribute, changeset, attribute, error)} + {:error, error} -> + {:cont, add_invalid_errors(value, :attribute, changeset, attribute, error)} - {:not_atomic, reason} -> - {:halt, {:not_atomic, reason}} - end - else - {:cont, - %{changeset | attributes: Map.put(changeset.attributes, attribute.name, value)}} + {:not_atomic, reason} -> + {:halt, {:not_atomic, reason}} end match?("_" <> _, key) -> @@ -992,19 +987,15 @@ defmodule Ash.Changeset do attribute = Ash.Resource.Info.attribute(changeset.resource, key) -> cond do attribute.name in action.accept -> - if Ash.Expr.expr?(value) do - case Ash.Type.cast_atomic(attribute.type, value, attribute.constraints) do - {:atomic, atomic} -> - {:cont, atomic_update(changeset, attribute.name, {:atomic, atomic})} + case Ash.Type.cast_atomic(attribute.type, value, attribute.constraints) do + {:atomic, atomic} -> + {:cont, atomic_update(changeset, attribute.name, {:atomic, atomic})} - {:error, error} -> - {:cont, add_invalid_errors(value, :attribute, changeset, attribute, error)} + {:error, error} -> + {:cont, add_invalid_errors(value, :attribute, changeset, attribute, error)} - {:not_atomic, reason} -> - {:halt, {:not_atomic, reason}} - end - else - {:cont, force_change_attribute(changeset, attribute.name, value)} + {:not_atomic, reason} -> + {:halt, {:not_atomic, reason}} end key in List.wrap(opts[:skip_unknown_inputs]) -> @@ -1477,13 +1468,6 @@ defmodule Ash.Changeset do end end - @doc false - def move_attributes_to_atomics(changeset) do - Enum.reduce(changeset.attributes, changeset, fn {key, value}, changeset -> - %{changeset | atomics: Keyword.put_new(changeset.atomics, key, value)} - end) - end - @doc false def handle_allow_nil_atomics(changeset, actor) do changeset.atomics @@ -2386,7 +2370,8 @@ defmodule Ash.Changeset do end end - defp add_atomic_validations(changeset, actor, opts) do + @doc false + def add_atomic_validations(changeset, actor, opts) do eager? = Keyword.get(opts, :eager?, true) changeset.atomic_validations