Error with composite `{:array, :atom}` field

I've started to get the following error for no apparent reason - the app was working fine, I've just updated deps and this happens inconsistently (sometime the app works fine, then I'll restart the dev server and it will be broken): cannot load ``["admin"]`` as type {:array, {:parameterized, Ash.Type.Atom.EctoType, []}} for field :roles in #Crm.Accounts.User The attribute looks like:
attribute :roles, {:array, :atom} do
allow_nil? false
default []
constraints nil_items?: false
end
attribute :roles, {:array, :atom} do
allow_nil? false
default []
constraints nil_items?: false
end
1 Reply
dblack
dblackOP3y ago
As identified by Zach, the issue is around to_existing_atom. Even though I'm using the atom elsewhere in the app, adding the atom to the one_of constraints for the field fixed the issue:
attribute :roles, {:array, :atom} do
allow_nil? false
default []

constraints nil_items?: false,
items: [one_of: [:admin, :user]]
end
attribute :roles, {:array, :atom} do
allow_nil? false
default []

constraints nil_items?: false,
items: [one_of: [:admin, :user]]
end

Did you find this page helpful?