Skip to content

Commit

Permalink
fix: handle casting nil vectors (#1316)
Browse files Browse the repository at this point in the history
  • Loading branch information
hwuethrich authored Jul 17, 2024
1 parent dd5bf4a commit dad0bfd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/ash/type/vector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ defmodule Ash.Type.Vector do
end

@impl true
def cast_input(nil, _), do: {:ok, nil}

def cast_input(value, _) do
Ash.Vector.new(value)
end
Expand Down
6 changes: 6 additions & 0 deletions test/type/vector_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ defmodule Ash.Test.Type.VectorTest do
assert {:ok, ^vector} = Ash.Type.dump_to_native(Ash.Type.Vector, list)
assert {:ok, ^vector} = Ash.Type.dump_to_native(Ash.Type.Vector, vector)
end

test "it casts nil to nil" do
assert {:ok, nil} = Ash.Type.cast_input(Ash.Type.Vector, nil)
assert {:ok, nil} = Ash.Type.cast_stored(Ash.Type.Vector, nil)
assert {:ok, nil} = Ash.Type.dump_to_native(Ash.Type.Vector, nil)
end
end

0 comments on commit dad0bfd

Please sign in to comment.