From 35b1278830a8e4a75bc9d8060975c141b7a8b5e9 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Tue, 23 May 2023 10:45:31 -0400 Subject: [PATCH] fix: don't notify unless `notify?: true` in bulk creates --- lib/ash/actions/create/bulk.ex | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/ash/actions/create/bulk.ex b/lib/ash/actions/create/bulk.ex index 820e4ecd..30183d52 100644 --- a/lib/ash/actions/create/bulk.ex +++ b/lib/ash/actions/create/bulk.ex @@ -657,6 +657,13 @@ defmodule Ash.Actions.Create.Bulk do {changeset, %{notifications: new_notifications}} = Ash.Changeset.run_before_actions(changeset) + new_notifications = + if opts[:notify?] do + new_notifications + else + [] + end + if changeset.valid? do {[changeset | changesets], invalid, notifications ++ new_notifications} else @@ -840,7 +847,13 @@ defmodule Ash.Actions.Create.Bulk do {[], notifications, changesets_by_index, []}, fn result, {results, notifications, changesets_by_index, errors} -> changeset = changesets_by_index[result.__metadata__.bulk_create_index] - notifications = notifications ++ [notification(changeset, result, opts)] + + notifications = + if opts[:notify?] do + [notification(changeset, result, opts) | notifications] + else + notifications + end try do case Ash.Changeset.run_after_transactions({:ok, result}, changeset) do