fix: prepare change with nil old value on union type change

This commit is contained in:
Zach Daniel 2023-12-12 18:10:34 -05:00
parent 839937bf6e
commit 352e27a153

View file

@ -734,6 +734,21 @@ defmodule Ash.Type.Union do
end
end
def prepare_change(
%Ash.Union{},
%Ash.Union{type: type_name, value: new_value},
constraints
) do
with {:ok, type_configs} <- Keyword.fetch(constraints, :types),
{:ok, type_config} <- Keyword.fetch(type_configs, type_name),
{:ok, type} <- Keyword.fetch(type_config, :type),
type_constraints <- Keyword.get(type_config, :constraints, []),
type <- Ash.Type.get_type(type),
{:ok, value} <- type.prepare_change(nil, new_value, type_constraints) do
{:ok, %Ash.Union{type: type_name, value: value}}
end
end
def prepare_change(%Ash.Union{type: type_name, value: old_value}, new_value, constraints)
when is_map(new_value) do
constraints