Skip to content

Commit

Permalink
test: demonstrate error with bulk update on manual action (#1204)
Browse files Browse the repository at this point in the history
The following error is produced

1) test manual updates are supported (Ash.Test.Actions.BulkUpdateTest)
     test/actions/bulk/bulk_update_test.exs:358
     ** (CaseClauseError) no case clause matching: nil
     code: |> Ash.bulk_update!(:update_manual, %{},
     stacktrace:
       (ash 3.0.7) lib/ash/actions/update/bulk.ex:2076: anonymous fn/11 in Ash.Actions.Update.Bulk.run_batch/10
       (elixir 1.16.2) lib/enum.ex:1264: anonymous fn/3 in Enum.flat_map/2
       (stdlib 5.0.2) maps.erl:416: :maps.fold_1/4
       (elixir 1.16.2) lib/enum.ex:2540: Enum.flat_map/2
       (ash 3.0.7) lib/ash/actions/update/bulk.ex:1966: Ash.Actions.Update.Bulk.run_batch/10
       (ash 3.0.7) lib/ash/actions/update/bulk.ex:1505: Ash.Actions.Update.Bulk.do_handle_batch/13
       (ash 3.0.7) lib/ash/actions/update/bulk.ex:1042: anonymous fn/12 in Ash.Actions.Update.Bulk.do_stream_batches/7
       (elixir 1.16.2) lib/stream.ex:613: anonymous fn/4 in Stream.map/2
       (elixir 1.16.2) lib/stream.ex:1816: anonymous fn/3 in Enumerable.Stream.reduce/3
       (elixir 1.16.2) lib/stream.ex:273: anonymous fn/4 in Stream.chunk_while_fun/2
       (elixir 1.16.2) lib/stream.ex:1159: anonymous fn/3 in Stream.with_index/2
       (elixir 1.16.2) lib/stream.ex:1079: Stream.do_transform_each/3
       (elixir 1.16.2) lib/stream.ex:1816: anonymous fn/3 in Enumerable.Stream.reduce/3
       (elixir 1.16.2) lib/enum.ex:4839: Enumerable.List.reduce/3
       (elixir 1.16.2) lib/stream.ex:1027: Stream.do_transform_inner_list/7
       (elixir 1.16.2) lib/stream.ex:1828: Enumerable.Stream.do_each/4
       (elixir 1.16.2) lib/stream.ex:1052: Stream.do_transform_inner_enum/7
       (elixir 1.16.2) lib/stream.ex:1828: Enumerable.Stream.do_each/4
       (elixir 1.16.2) lib/stream.ex:943: Stream.do_transform/5
       (elixir 1.16.2) lib/enum.ex:4396: Enum.reverse/1
       (elixir 1.16.2) lib/enum.ex:3728: Enum.to_list/1
       (ash 3.0.7) lib/ash/actions/update/bulk.ex:1070: Ash.Actions.Update.Bulk.run_batches/3
       (ash 3.0.7) lib/ash/actions/update/bulk.ex:386: Ash.Actions.Update.Bulk.run/6
       (ash 3.0.7) lib/ash.ex:2209: Ash.bulk_update!/4
       test/actions/bulk/bulk_update_test.exs:373: (test)
  • Loading branch information
ahey authored May 27, 2024
1 parent 6de8e76 commit 2ee311b
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/actions/bulk/bulk_update_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ defmodule Ash.Test.Actions.BulkUpdateTest do
end
end

defmodule ManualUpdate do
use Ash.Resource.ManualUpdate

Check warning on line 106 in test/actions/bulk/bulk_update_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (SimpleSat) / mix credo --strict

There should be no trailing white-space at the end of a line.

Check warning on line 106 in test/actions/bulk/bulk_update_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (Picosat) / mix credo --strict

There should be no trailing white-space at the end of a line.
def update(changeset, _opts, _context) do
{:ok, changeset.data}
end
end

Check warning on line 111 in test/actions/bulk/bulk_update_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (SimpleSat) / mix credo --strict

There should be no trailing white-space at the end of a line.

Check warning on line 111 in test/actions/bulk/bulk_update_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (Picosat) / mix credo --strict

There should be no trailing white-space at the end of a line.
defmodule Post do
@moduledoc false
use Ash.Resource,
Expand All @@ -117,6 +125,10 @@ defmodule Ash.Test.Actions.BulkUpdateTest do
default_accept :*
defaults [:read, :destroy, create: :*, update: :*]

update :update_manual do
manual ManualUpdate
end

Check warning on line 131 in test/actions/bulk/bulk_update_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (SimpleSat) / mix credo --strict

There should be no trailing white-space at the end of a line.

Check warning on line 131 in test/actions/bulk/bulk_update_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (Picosat) / mix credo --strict

There should be no trailing white-space at the end of a line.
update :update_with_change do
require_atomic? false

Expand Down Expand Up @@ -341,6 +353,33 @@ defmodule Ash.Test.Actions.BulkUpdateTest do
Enum.sort_by(records, & &1.title)
end)
end

Check warning on line 356 in test/actions/bulk/bulk_update_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (SimpleSat) / mix credo --strict

There should be no trailing white-space at the end of a line.

Check warning on line 356 in test/actions/bulk/bulk_update_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (Picosat) / mix credo --strict

There should be no trailing white-space at the end of a line.
test "manual updates are supported" do

Check failure on line 357 in test/actions/bulk/bulk_update_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (SimpleSat) / mix test

test manual updates are supported (Ash.Test.Actions.BulkUpdateTest)

Check failure on line 357 in test/actions/bulk/bulk_update_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (Picosat) / mix test

test manual updates are supported (Ash.Test.Actions.BulkUpdateTest)
assert %Ash.BulkResult{
records: [
%{title: "title1"},
%{title: "title2"}
]
} =
Ash.bulk_create!([%{title: "title1"}, %{title: "title2"}], Post, :create,
return_stream?: true,
return_records?: true,
authorize?: false
)
|> Stream.map(fn {:ok, result} ->
result
end)
|> Ash.bulk_update!(:update_manual, %{},
resource: Post,
strategy: :stream,
return_records?: true,
return_errors?: true,
authorize?: false
)
|> Map.update!(:records, fn records ->
Enum.sort_by(records, & &1.title)
end)
end

test "accepts arguments" do
assert %Ash.BulkResult{
Expand Down

0 comments on commit 2ee311b

Please sign in to comment.