fix: don't gather notifications except for in the top level transaction starter

chore: format
This commit is contained in:
Zach Daniel 2024-07-24 12:02:55 -04:00
parent ed30dcf1dd
commit 228eda86ff
2 changed files with 10 additions and 8 deletions

View file

@ -551,7 +551,9 @@ defmodule Ash.Actions.Update.Bulk do
fn result, {results, errors, error_count, notifications} ->
# we can't actually know if the changeset changed or not when doing atomics
# so we just have to set it to statically true here.
atomic_changeset = Ash.Changeset.set_context(atomic_changeset, %{changed?: true})
atomic_changeset =
Ash.Changeset.set_context(atomic_changeset, %{changed?: true})
case Ash.Changeset.run_after_actions(result, atomic_changeset, []) do
{:error, error} ->
if opts[:transaction] && opts[:rollback_on_error?] do

View file

@ -3084,7 +3084,7 @@ defmodule Ash.Changeset do
)
|> case do
{:ok, {:ok, value, changeset, instructions}} ->
{:ok, value, changeset, instructions}
{:ok, value, changeset, Map.put(instructions, :gather_notifications?, notify?)}
{:ok, {:error, error}} ->
{:error, error}
@ -3133,17 +3133,17 @@ defmodule Ash.Changeset do
{:ok, value, changeset, Map.put(instructions, :notifications, [])}
else
notifications =
List.wrap(Process.delete(:ash_notifications)) ++
(instructions[:notifications] || [])
instructions[:notifications] || []
notifications =
if opts[:return_notifications?] do
notifications
if instructions[:gather_notifications?] do
Enum.concat(List.wrap(Process.get(:ash_notifications, [])), notifications)
else
Ash.Notifier.notify(notifications)
notifications
end
{:ok, value, changeset, Map.put(instructions, :notifications, notifications)}
{:ok, value, changeset,
Map.put(instructions, :notifications, Ash.Notifier.notify(notifications))}
end
end