From cac6397e2de034f7956bec877b7764bee0fd9ae8 Mon Sep 17 00:00:00 2001 From: Barnabas Jovanovics Date: Wed, 20 Nov 2024 02:12:14 +0100 Subject: [PATCH] fix: store notifications from simple results (#1591) --- lib/ash/actions/create/bulk.ex | 12 ++++++++++++ lib/ash/actions/destroy/bulk.ex | 18 ++++++++++++++++++ lib/ash/actions/update/bulk.ex | 11 +++++++++++ 3 files changed, 41 insertions(+) diff --git a/lib/ash/actions/create/bulk.ex b/lib/ash/actions/create/bulk.ex index c27825aad..ec59db580 100644 --- a/lib/ash/actions/create/bulk.ex +++ b/lib/ash/actions/create/bulk.ex @@ -472,6 +472,17 @@ defmodule Ash.Actions.Create.Bulk do }) ] + {:ok, result, notifications} -> + Process.put({:any_success?, ref}, true) + + store_notification(ref, notifications, opts) + + [ + Ash.Resource.set_metadata(result, %{ + bulk_create_index: changeset.context.bulk_create.index + }) + ] + {:error, error} -> store_error(ref, error, opts) [] @@ -498,6 +509,7 @@ defmodule Ash.Actions.Create.Bulk do Ash.DataLayer.transaction( List.wrap(resource) ++ action.touches_resources, fn -> + # TODO: check the difference bewteen ref handeling here and in bulk_update tmp_ref = make_ref() result = diff --git a/lib/ash/actions/destroy/bulk.ex b/lib/ash/actions/destroy/bulk.ex index 89ed1990e..d5baa3117 100644 --- a/lib/ash/actions/destroy/bulk.ex +++ b/lib/ash/actions/destroy/bulk.ex @@ -1385,6 +1385,24 @@ defmodule Ash.Actions.Destroy.Bulk do }) ] + {:ok, notifications} -> + Process.put({:any_success?, ref}, true) + + store_notification(ref, notifications, opts) + + [] + + {:ok, result, notifications} -> + Process.put({:any_success?, ref}, true) + + store_notification(ref, notifications, opts) + + [ + Ash.Resource.set_metadata(result, %{ + bulk_destroy_index: changeset.context.bulk_destroy.index + }) + ] + {:error, error} -> store_error(ref, error, opts) [] diff --git a/lib/ash/actions/update/bulk.ex b/lib/ash/actions/update/bulk.ex index 04866a1e5..da82b5e86 100644 --- a/lib/ash/actions/update/bulk.ex +++ b/lib/ash/actions/update/bulk.ex @@ -1679,6 +1679,17 @@ defmodule Ash.Actions.Update.Bulk do }) ] + {:ok, result, notifications} -> + Process.put({:any_success?, ref}, true) + + store_notification(ref, notifications, opts) + + [ + Ash.Resource.set_metadata(result, %{ + metadata_key => changeset.context |> Map.get(context_key) |> Map.get(:index) + }) + ] + {:error, error} -> store_error(ref, error, opts) []