ash-project / ash-project/ash

Using custom types on embedded resources throws an error

Open
#860 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Elixir
Stars
2.5k
Forks
422
Avg merge
23h 26m
Merged PRs (30d)
46

Description

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:

```elixir
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:

```elixir
%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.

Contributor guide

Open the contributing guide

Research direction

The issue names no source files or tests; start by reproducing the embedded Ash.Resource example with the custom volume and money types, then compare it with the non-embedded case. Trace where the embedded value reaches Jason encoding, and consider the issue done when custom and native types no longer raise the reported Protocol.UndefinedError.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.