ash-project/ash_admin

LiveView crash when removing one element of a many-to-many relationship on a Create form

sevenseacat opened this issue · 5 comments

Describe the bug
On a Create form for a new resource that has a many-to-many relationship with another resource, Ash admin builds a section to add/remove new records of the relationship. eg. in our app we have a resource that has many_to_many :competencies:

Screen Shot 2022-05-18 at 3 49 01 pm

When clicking the minus icon to remove one of the items in the list, the LiveView crashes:

** (Protocol.UndefinedError) protocol Phoenix.HTML.FormData not implemented for #Ash.Changeset<action_type: :create, action: :create, (lots of other stuff omitted)> of type Ash.Changeset (a struct). This protocol is implemented for the following type(s): AshPhoenix.FilterForm, AshPhoenix.FilterForm.Predicate, AshPhoenix.Form, Atom, Ecto.Changeset, Plug.Conn
    (phoenix_html 3.2.0) lib/phoenix_html/form_data.ex:1: Phoenix.HTML.FormData.impl_for!/1
    (phoenix_html 3.2.0) lib/phoenix_html/form_data.ex:34: Phoenix.HTML.FormData.input_value/3
    (ash_admin 0.4.4) lib/ash_admin/components/resource/form.ex:1119: AshAdmin.Components.Resource.Form.remove_value/3
    (ash_admin 0.4.4) lib/ash_admin/components/resource/form.ex:1036: AshAdmin.Components.Resource.Form.handle_event/3

Expected behavior
The element (form field and minus icon) should be removed from the page, without LiveView crashing.

** Runtime

  • Elixir version - 1.13.3
  • Erlang version - 24.3
  • OS - MacOS Monterey 12.3
  • Ash version - main branch (sha 0f24ac78ae6a551c30e7d45419672c0ed72dbd64)
  • Ash admin version - 0.4.4

🤔 Yeah, that looks pretty suspect...can you try using the latest release candidate of ash_admin and see if that resolves the issue? I've pinned it to the latest release candidate of AshPhoenix which has had a lot of work done on those operations.

@zachdaniel I've just tried this with the latest release and unfortunately still seeing the same issue. This is happening in a couple of places in our project - I've also had the issue with coordinate fields on another resource:
Screen Shot 2022-05-19 at 8 59 49 am
Since our coords don't have a :many_to_many this might be an issue with the forms themselves?

I've pushed a potential fix up to main. I'm not sure if I reproduced the exact bug you're seeing, but I definitely at least fixed a similar one 😄

I'll pull down main (for all Ash-related repos) and give it a test :)

The issue appears to be resolved :D I can now and add remove elements on that page no problem, the correct one gets removed when I press the minus icon, no crash anymore!