diff --git a/lib/ash/actions/update/bulk.ex b/lib/ash/actions/update/bulk.ex index bb3b0e5f..a8e02364 100644 --- a/lib/ash/actions/update/bulk.ex +++ b/lib/ash/actions/update/bulk.ex @@ -45,8 +45,7 @@ defmodule Ash.Actions.Update.Bulk do fully_atomic_changeset = cond do !Enum.empty?(query.before_action) -> - {:not_atomic, - "cannot atomically update a query if it has `before_action` hooks"} + {:not_atomic, "cannot atomically update a query if it has `before_action` hooks"} not_atomic_reason -> {:not_atomic, not_atomic_reason} @@ -195,7 +194,8 @@ defmodule Ash.Actions.Update.Bulk do # having after action hooks. Or perhaps we need to stream the ids and then bulk update # them. opts = - if has_after_batch_hooks? || !Enum.empty?(atomic_changeset.after_action) || opts[:notify?] do + if has_after_batch_hooks? || !Enum.empty?(atomic_changeset.after_action) || + opts[:notify?] do Keyword.put(opts, :return_records?, true) else opts @@ -478,32 +478,36 @@ defmodule Ash.Actions.Update.Bulk do {results, []} end - {results, errors, error_count, notifications} = - if Enum.empty?(atomic_changeset.after_action) do - {results, [], 0, notifications} - else - Enum.reduce(results, {[], [], 0, notifications}, fn result, {results, errors, error_count, notifications} -> - case Ash.Changeset.run_after_actions(result, atomic_changeset, []) do - {:error, error} -> - if opts[:transaction] && opts[:rollback_on_error?] do - if Ash.DataLayer.in_transaction?(atomic_changeset.resource) do - Ash.DataLayer.rollback( - atomic_changeset.resource, - error - ) - end + {results, errors, error_count, notifications} = + if Enum.empty?(atomic_changeset.after_action) do + {results, [], 0, notifications} + else + Enum.reduce(results, {[], [], 0, notifications}, fn result, + {results, errors, error_count, + notifications} -> + case Ash.Changeset.run_after_actions(result, atomic_changeset, []) do + {:error, error} -> + if opts[:transaction] && opts[:rollback_on_error?] do + if Ash.DataLayer.in_transaction?(atomic_changeset.resource) do + Ash.DataLayer.rollback( + atomic_changeset.resource, + error + ) end + end - {results, errors ++ List.wrap(error), error_count + Enum.count(List.wrap(error)), notifications} + {results, errors ++ List.wrap(error), + error_count + Enum.count(List.wrap(error)), notifications} - {:ok, result, _changeset, %{notifications: more_new_notifications}} -> - {[result | results], errors, error_count, notifications ++ more_new_notifications} - end - end) - |> then(fn {results, errors, error_count, notifications} -> - {Enum.reverse(results), errors, error_count, notifications} - end) - end + {:ok, result, _changeset, %{notifications: more_new_notifications}} -> + {[result | results], errors, error_count, + notifications ++ more_new_notifications} + end + end) + |> then(fn {results, errors, error_count, notifications} -> + {Enum.reverse(results), errors, error_count, notifications} + end) + end {results, errors, error_count} = case load_data( diff --git a/lib/ash/changeset/changeset.ex b/lib/ash/changeset/changeset.ex index 891ba39a..8c554b25 100644 --- a/lib/ash/changeset/changeset.ex +++ b/lib/ash/changeset/changeset.ex @@ -605,9 +605,6 @@ defmodule Ash.Changeset do {:not_atomic, reason} -> {:not_atomic, reason} - {:error, error} -> - {:error, error} - changeset -> clear_phase(changeset) end