Ash.Resource update error: Postgrex.Error) ERROR 42804 (datatype_mismatch) column "roles" is of type jsonb[]

I have this code:

defmodule Project.Role do
  use Ash.Resource,
    data_layer: AshPostgres.DataLayer

  attributes do
    uuid_primary_key(:id)
    create_timestamp(:inserted_at)
    update_timestamp(:updated_at)
    attribute(:name, :string, allow_nil?: false)
    attribute(:roles, {:array, :map})
  end

  code_interface do
    define_for(Project.Resource)
    define(:create, action: :create)
    define(:update, action: :update)
    define(:destroy, action: :destroy)
  end

  actions do
    defaults([:create, :read, :update, :destroy])
  end
end

iex> roles = [%{section: :client, actions[:create, :update]}, %{section: :product, actions[:create, :update]}]
iex> role = Project.Role.create! %{name: "test", roles: roles}
iex> Project.Role.update! role, %{name: "test 2", roles: roles}

No problem for create, but, when if update, show an error.

** (EXIT from #PID<0.536.0>) an exception was raised:
         ** (Ash.Error.Unknown) Unknown Error
     
     * ** (Postgrex.Error) ERROR 42804 (datatype_mismatch) column "roles" is of type jsonb[] but expression is of type text[]

This definitely looks like a bug. Are you on the latest version of ash_postgres?

1 Like

1.5.16

Was just going to say, I was able to reproduce the issue on latest :laughing: Will get back to you w/ a fix.

1 Like

Tks and i will wait the fix

Fixed in 1.5.17

1 Like

Tks very much!