AshPhoenix.Form fails in submit without errors with embedded resources
I have a embedded resource like this:
This embedded resource is used as an attribute inside my
Property
resource like so: attribute :off_market, OffMarket, allow_nil?: true
I'm having problems when trying to submit an update to it using AshPhoenix.Form.submit
, when I run this, it will fail with a {:error, form}
reply but there will be no error inside the form.
This is how I initialize the form:
After this, I just run the submit function. An I doing something wrong here?25 Replies
I'm not sure if only the information I gave is enough to see what the issue is, but at the same time my resources are pretty big, so what I did was to convert the form struct into a base64 so you can actually load it directly in elixir code if you think that will help
To load these files, you just need to paste the base64 content into a elixir string and then do
string |> Base.decode64!() |> :erlang.binary_to_term()
The first thing to check is, on the errored form, what this returns:
The second thing is to look and see if you see any log messages about unhandled errors
the third thing is to see what happens if you submit the form with
force?: true
Thanks! I was not aware of the
for_path: :all
option!
Running it I got:
But I still don't get that is the problem, here is the nested form of one of these errors:it says in the
submit_errors
that it contains errors, but I don't get why is that, it says that the :type
, :url
and :s3_path
attributes are required, but they are clearly filled in the form 🤔
In case this helps, here is the image and sub_image resources:
Are you validatitng the form on input?
like
phx-change="validate"
?Yes, but in this case I'm running it manually jsut to get the functions reply.
Basically my in-code submit function looks more like this:
This will give the same errors as shown above
🤔 something seems strange there
you're providing the images manually?
what does
params
look like aftter your maybe_process_params/1
call?maybe_process_params is just to "change" some fields, but it is not related to the images resource.
Yes, The :uploaded_images and :removed_images are arguments that I use in a change to create a oban job to process the images before actually inserting them in the db (adding watermark, etc), so it is not actually related to the
:images
field of the property in this stage.
The images from the form that are returning errors are actually images that are alraedy in the DB, what I don't get is why they are failing since we are just updating the resource without actually making any change to the images at all
I will see if I can make the scope smaller just to try to make it easier to understandThe question stands about what the params look like that are being passed in
I pass the form.params to it, it would be an empty map in this case
%{}
You've confirmed that for sure?
Just want to make sure all our ducks are in a row 🙂
If you could potentially make a test reproduction in the ash_phoenix tests and/or push something up that I can pull down to reproduce then I could take a look
I will try to create a unit test, but here is a small examply that can reproduce the issue:
And then run:
So, @Zach Daniel I created a unit test for it in AshPhoenix, but weirdly enough I can't reproduce it running from it, only inside my project, even thought the code and libraries versions are exactly the same
I will try to move it into a separated small project and see if I can reproduce it there
🤔 strange
The only thing that I can think that is different is that I have more ash libraries in my project, ash_authentication_phoenix, ash_graphql, etc. But I'm not using them in these resources, so I'm not sure if they somehow affect AshPhoenix.Form in some way
As far as I know, they shouldn't
perhaps its fixed in the main branch of ash_phoenix or something?
You mean in my project? I looked into mix.lock and it is getting the latest version
I will try to move it to another standalone project right now and see if I can make it trigger, hopefully I will be able to do that and give you a link to the project at least 😅
All right! I was able to create a small project that reproduces the issue
https://github.com/sezaru/ash_phoenix_embedded_test
@Zach Daniel when you have some free time can you try it out? Basically you just need to open iex and run:
Definitely something strange here...
I feel like if updating embeds didn't work that I'd have heard about it before now 😆
but the reproduction is pretty clear
maybe it only doesn't work on arrays? not sure
found it 🙂
Damn that was fast!
when I have a reproduction, I can always fix things very fast ❤️
okay, pushed to main
Can confirm, that fixed it!
Not sure why I couldn't trigger it when I run the same code but as a ash_phoenix unit test 🤔
¯\_(ツ)_/¯