ash-project / ash

A declarative, extensible framework for building Elixir applications.
https://www.ash-hq.org
MIT License
1.61k stars 216 forks source link

Using custom types on embedded resources throws an error #860

Open gordoneliel opened 8 months ago

gordoneliel commented 8 months ago

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.

zachdaniel commented 8 months ago

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.