fix: incorrect error for casting binary UUID (#653)

This commit is contained in:
skanderm 2023-07-11 20:35:01 -04:00 committed by GitHub
parent 8e12a14b25
commit 925f5c1f9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -23,7 +23,10 @@ defmodule Ash.Type.UUID do
def cast_input(nil, _), do: {:ok, nil}
def cast_input(value, _) when is_binary(value) do
Ecto.Type.cast(Ecto.UUID, String.trim(value))
case String.valid?(value) do
true -> Ecto.Type.cast(Ecto.UUID, String.trim(value))
false -> Ecto.Type.cast(Ecto.UUID, value)
end
end
def cast_input(value, _) do

11
test/type/uuid_test.exs Normal file
View file

@ -0,0 +1,11 @@
defmodule Ash.Test.Type.UUIDTest do
@moduledoc false
use ExUnit.Case, async: true
test "it casts binary UUIDs to string" do
uuid = "a7cec9ba-15de-4c56-99e4-c2abc91a2209"
assert {:ok, binary_uuid} = Ash.Type.dump_to_native(Ash.Type.UUID, uuid)
assert {:ok, ^uuid} = Ash.Type.cast_input(Ash.Type.UUID, binary_uuid)
end
end