Skip to content

Commit

Permalink
fix: fix match validation when performed atomically
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed May 3, 2024
1 parent a3418e3 commit 1bdc095
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/ash/resource/validation/match.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ defmodule Ash.Resource.Validation.Match do
{:not_atomic, "can't match on an atomic expression"}

true ->
changeset =
if Keyword.has_key?(changeset.atomics, opts[:attribute]) do
%{
changeset
| attributes:
Map.put(
changeset.attributes,
opts[:attribute],
changeset.atomics[opts[:attribute]]
)
}
else
changeset
end

validate(changeset, opts, context)
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/actions/bulk/bulk_update_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ defmodule Ash.Test.Actions.BulkUpdateTest do
create_records = fn count ->
Stream.iterate(1, &(&1 + 1))
|> Stream.map(fn i -> %{title: "title#{i}"} end)
|> Stream.take(count)
|> Ash.bulk_create!(Post, :create, return_stream?: true, return_records?: true)
|> Stream.map(fn {:ok, result} -> result end)
|> Stream.take(count)
end

update_records = fn records, opts ->
Expand Down Expand Up @@ -459,7 +459,7 @@ defmodule Ash.Test.Actions.BulkUpdateTest do
result
end)
|> Ash.bulk_update(:update_with_match, %{title4: "INVALID"},
strategy: :atomic_batches,
strategy: :atomic,
resource: Post,
return_errors?: true,
authorize?: false
Expand Down

0 comments on commit 1bdc095

Please sign in to comment.