Fix generated change/3 function when only implementing batch_change/3 (#1415)

This commit is contained in:
Hannes Wüthrich 2024-08-28 14:04:52 +02:00 committed by GitHub
parent 55f1ead24f
commit 4a75743812
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 8 deletions

View file

@ -213,7 +213,7 @@ defmodule Ash.Resource.Change do
Ash.Changeset.before_action(changeset, fn changeset ->
{[changeset], notifications} =
Enum.split_with(
before_batch([changeset], opts, context),
apply(__MODULE__, :before_batch, [[changeset], opts, context]),
fn %Ash.Notifier.Notification{} ->
false
end
@ -224,14 +224,13 @@ defmodule Ash.Resource.Change do
else
changeset
end
|> Ash.Changeset.before_action(changeset, fn change ->
|> Ash.Changeset.before_action(fn changeset ->
Enum.at(batch_change([changeset], opts, context), 0)
end)
|> then(fn changeset ->
if has_after_batch?() do
Ash.Changeset.after_action(changeset, fn changeset, result ->
[{changeset, result}]
|> after_batch(opts, context)
apply(__MODULE__, :after_batch, [[{changeset, result}], opts, context])
|> Enum.reduce({[], [], []}, fn item, {records, errors, notifications} ->
case item do
{:ok, record} -> {[record | records], errors, notifications}

View file

@ -18,10 +18,6 @@ defmodule Ash.Test.Actions.BulkCreateTest do
defmodule AddAfterToTitle do
use Ash.Resource.Change
def change(_, _, _) do
raise "can't get here"
end
def batch_change(changesets, _, _) do
changesets
end