AF
Ash Framework•4mo ago
quartz

Unable to send a `Ash.Type.File` as argument to action using `AshPhoenix.Form`

When trying to send a Ash.Type.File struct as an argument to an update action, AshPhoenix.Form is failing on validation. Worth nothing that sending the file argument as :override_params in AshPhoenix.Form.submit does bypass this and work correctly, as does calling the action directly. AshAdmin also exhibits this behaviour. Am I doing something wrong or is this a bug? The action looks like this:
update :update_avatar do
require_atomic? false
accept []
argument :avatar, Ash.Type.File, allow_nil?: true
argument :filename, :string, allow_nil?: true

change &handle_avatar/2 # actually saves the file and stores path to DB
end
update :update_avatar do
require_atomic? false
accept []
argument :avatar, Ash.Type.File, allow_nil?: true
argument :filename, :string, allow_nil?: true

change &handle_avatar/2 # actually saves the file and stores path to DB
end
4 Replies
quartz
quartzOP•4mo ago
Stacktrace:
Unknown Error

* ** (Protocol.UndefinedError) protocol Enumerable not implemented for type Ash.Type.File (a struct)

Got value:

%Ash.Type.File{
source: "/var/folders/62/g1mq6h310cbc7k4r6g1c6v300000gn/T/12fcca4106/test.csv",
implementation: Ash.Type.File.Path
}

(elixir 1.18.4) lib/enum.ex:1: Enumerable.impl_for!/1
(elixir 1.18.4) lib/enum.ex:166: Enumerable.reduce/3
(elixir 1.18.4) lib/enum.ex:1574: Enum.reduce_into_protocol/3
(elixir 1.18.4) lib/enum.ex:1558: Enum.into_protocol/2
(ash 3.5.25) lib/ash/changeset/changeset.ex:2984: Ash.Changeset.cast_params/4
(ash 3.5.25) lib/ash/changeset/changeset.ex:2706: Ash.Changeset.handle_params/4
(ash 3.5.25) lib/ash/changeset/changeset.ex:2543: Ash.Changeset.do_for_action/4
(ash_phoenix 2.3.9) lib/ash_phoenix/form/form.ex:610: AshPhoenix.Form.for_create/3
(ash_phoenix 2.3.9) lib/ash_phoenix/form/form.ex:1619: anonymous fn/7 in AshPhoenix.Form.validate_nested_forms/6
(elixir 1.18.4) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash_phoenix 2.3.9) lib/ash_phoenix/form/form.ex:1264: AshPhoenix.Form.validate/3
(ash_phoenix 2.3.9) lib/ash_phoenix/form/form.ex:2034: AshPhoenix.Form.submit/2
(ash_phoenix 2.3.9) lib/ash_phoenix/form/form.ex:1997: AshPhoenix.Form.submit/2
(ash_admin 0.13.11) lib/ash_admin/components/resource/form.ex:1837: AshAdmin.Components.Resource.Form.handle_event/3
Unknown Error

* ** (Protocol.UndefinedError) protocol Enumerable not implemented for type Ash.Type.File (a struct)

Got value:

%Ash.Type.File{
source: "/var/folders/62/g1mq6h310cbc7k4r6g1c6v300000gn/T/12fcca4106/test.csv",
implementation: Ash.Type.File.Path
}

(elixir 1.18.4) lib/enum.ex:1: Enumerable.impl_for!/1
(elixir 1.18.4) lib/enum.ex:166: Enumerable.reduce/3
(elixir 1.18.4) lib/enum.ex:1574: Enum.reduce_into_protocol/3
(elixir 1.18.4) lib/enum.ex:1558: Enum.into_protocol/2
(ash 3.5.25) lib/ash/changeset/changeset.ex:2984: Ash.Changeset.cast_params/4
(ash 3.5.25) lib/ash/changeset/changeset.ex:2706: Ash.Changeset.handle_params/4
(ash 3.5.25) lib/ash/changeset/changeset.ex:2543: Ash.Changeset.do_for_action/4
(ash_phoenix 2.3.9) lib/ash_phoenix/form/form.ex:610: AshPhoenix.Form.for_create/3
(ash_phoenix 2.3.9) lib/ash_phoenix/form/form.ex:1619: anonymous fn/7 in AshPhoenix.Form.validate_nested_forms/6
(elixir 1.18.4) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash_phoenix 2.3.9) lib/ash_phoenix/form/form.ex:1264: AshPhoenix.Form.validate/3
(ash_phoenix 2.3.9) lib/ash_phoenix/form/form.ex:2034: AshPhoenix.Form.submit/2
(ash_phoenix 2.3.9) lib/ash_phoenix/form/form.ex:1997: AshPhoenix.Form.submit/2
(ash_admin 0.13.11) lib/ash_admin/components/resource/form.ex:1837: AshAdmin.Components.Resource.Form.handle_event/3
ZachDaniel
ZachDaniel•4mo ago
🤔 something is strange there for sure It seems like you're passing an individual file when a map of params is expected though
quartz
quartzOP•4mo ago
yeah it was working some time ago I remember, and like I said above, same problem happens in AshAdmin
ZachDaniel
ZachDaniel•4mo ago
🤔 interesting. Can you create a reproduction project and open an issue?

Did you find this page helpful?