ash-project/ash_admin

Can't update value of a `map`-type field

sevenseacat opened this issue · 3 comments

Describe the bug

When updating and saving a record for a resource that has a map field in it, an error is generated and the resource won't save.

Resource:

defmodule MyApp.Accounts.UserSetting do 
  use Ash.Resource,
    data_layer: AshPostgres.DataLayer,
    authorizers: [Ash.Policy.Authorizer]

  postgres do
    table "user_settings"
    repo MyApp.Repo

    references do
      reference :user, on_delete: :delete
    end
  end

  attributes do
    attribute :setting, :string, primary_key?: true, allow_nil?: false
    attribute :value, :map, allow_nil?: false
  end

  relationships do
    belongs_to :user, MyApp.Accounts.User do
      primary_key? true
      allow_nil? false
    end
  end

  # Other unrelated stuff (I think) omitted

UI:

Screenshot 2024-03-18 at 2 20 51 pm

Error:

Upon pressing Save, an error in red text is displayed at the top of the form:

Internal Error: ** (Protocol.UndefinedError) protocol Jason.Encoder not implemented for 
dynamic([], [ "934c5b0b-65d8-4448-b79d-29bcc375dfd5", "07884d7b-0031-4abf-9d3e-12558cdf01ca", 
"0118bb2a-9d18-4402-aba7-a81a3de0503e", "noun-goggles-3360310.svg", "noun-safety-1909223.svg" ]) 
of type Ecto.Query.DynamicExpr (a struct), Jason.Encoder protocol must always be explicitly 
implemented.

Runtime

  • Elixir version 1.15.4-otp-26
  • Erlang version 26.0.2
  • OS macOS Sonoma something
  • Ash version 2.20.1
  • Ash Admin 0.10.7

I think this was fixed in a recent version of ash or ash_postgres, I forget which one. Mind double checking if updating ash and ash_postgres resolves the issue?

I'm already on the latest versions of both - Ash 2.20.1 and AshPostgres 1.5.17

Fixed in latest ash/ash_postgres versions.