ash
ash copied to clipboard
Using custom types on embedded resources throws an error
When you try to add a custom type eg. ex_money, or your own custom type to an embedded field, it throws an error. I noticed this fails on some native elixir/ecto types like time as well.
Here is an example resource that embeds a custom volume type:
use Ash.Resource,
data_layer: :embedded
attributes do
attribute(:from_volume, :ash_volume, allow_nil?: false)
attribute(:to_volume, :ash_volume, allow_nil?: false)
attribute(:price, :ash_money, allow_nil?: false)
end
When running, the error below occurs:
%Ash.Error.Unknown{
errors: [%Ash.Error.Unknown.UnknownError{
error: "** (Protocol.UndefinedError) protocol Jason.Encoder not implemented for {\"cu_ft\", 0} of type Tuple, Jason.Encoder protocol must always be explicitly implemented. This protocol is implemented for the following type(s): Any, Ash.CiString, Ash.Union, Atom, BitString, Cldr.LanguageTag, Date, DateTime, Decimal, Ecto.Association.NotLoaded, Ecto.Schema.Metadata, ...
This error does not occur when the resource is not an embedded field.
Hey @gordoneliel if you could potentially add a failing test to the project to reproduce this issue I'd really appreciate it. I'm very busy at the moment and that can help me solve it much much faster.