ash icon indicating copy to clipboard operation
ash copied to clipboard

Using custom types on embedded resources throws an error

Open gordoneliel opened this issue 1 year ago • 1 comments

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.

gordoneliel avatar Jan 31 '24 00:01 gordoneliel

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.

zachdaniel avatar Jan 31 '24 02:01 zachdaniel