Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle notifications returned from simple results in bulk actions #1591

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/ash/actions/create/bulk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
[]
Expand All @@ -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 =
Expand Down
18 changes: 18 additions & 0 deletions lib/ash/actions/destroy/bulk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
[]
Expand Down
11 changes: 11 additions & 0 deletions lib/ash/actions/update/bulk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
[]
Expand Down
Loading