mathieuprog / polymorphic_embed

Polymorphic embeds in Ecto
Apache License 2.0
341 stars 63 forks source link

Regression for Form #30

Closed maennchen closed 3 years ago

maennchen commented 3 years ago

This commit introduces a regression for me: https://github.com/mathieuprog/polymorphic_embed/commit/0081ac2cef2b2dc2df354f1f43d5b3b93ae5f9fd

Installed Version: 1.3.3

The to_form function only works for me if the changeset is invalid, as soon as it is valid, I get an ArgumentError:

[error] GenServer #PID<0.1829.0> terminating
** (FunctionClauseError) no function clause matching in PolymorphicEmbed.HTML.Form.do_get_errors/1
    (polymorphic_embed 1.3.3) lib/html/form.ex:70: PolymorphicEmbed.HTML.Form.do_get_errors(%Acme.CaseContext.ProtocolEntry.Sms{delivery_receipt_id: nil, text: "f", uuid: nil})
    (polymorphic_embed 1.3.3) lib/html/form.ex:26: PolymorphicEmbed.HTML.Form.to_form/5
    (acme_web 0.0.0-noversion) lib/acme_web/live/polymorphic_inputs.ex:20: anonymous fn/4 in AcmeWeb.PolimorphicInputs.render/1
    (phoenix_live_view 0.15.3) lib/phoenix_live_view/diff.ex:342: Phoenix.LiveView.Diff.traverse/6
    (phoenix_live_view 0.15.3) lib/phoenix_live_view/diff.ex:430: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/6
    (elixir 1.11.3) lib/enum.ex:2193: Enum."-reduce/3-lists^foldl/2-0-"/3
    (phoenix_live_view 0.15.3) lib/phoenix_live_view/diff.ex:342: Phoenix.LiveView.Diff.traverse/6
    (phoenix_live_view 0.15.3) lib/phoenix_live_view/diff.ex:430: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/6
    (elixir 1.11.3) lib/enum.ex:2193: Enum."-reduce/3-lists^foldl/2-0-"/3
    (phoenix_live_view 0.15.3) lib/phoenix_live_view/diff.ex:342: Phoenix.LiveView.Diff.traverse/6
    (phoenix_live_view 0.15.3) lib/phoenix_live_view/diff.ex:430: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/6
    (elixir 1.11.3) lib/enum.ex:2193: Enum."-reduce/3-lists^foldl/2-0-"/3
    (phoenix_live_view 0.15.3) lib/phoenix_live_view/diff.ex:342: Phoenix.LiveView.Diff.traverse/6
    (phoenix_live_view 0.15.3) lib/phoenix_live_view/diff.ex:430: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/6
    (elixir 1.11.3) lib/enum.ex:2193: Enum."-reduce/3-lists^foldl/2-0-"/3
    (phoenix_live_view 0.15.3) lib/phoenix_live_view/diff.ex:342: Phoenix.LiveView.Diff.traverse/6
    (phoenix_live_view 0.15.3) lib/phoenix_live_view/diff.ex:584: Phoenix.LiveView.Diff.render_component/9
    (phoenix_live_view 0.15.3) lib/phoenix_live_view/diff.ex:529: anonymous fn/5 in Phoenix.LiveView.Diff.render_pending_components/6
    (elixir 1.11.3) lib/enum.ex:2193: Enum."-reduce/3-lists^foldl/2-0-"/3
    (stdlib 3.13.2) maps.erl:233: :maps.fold_1/3

Changeset at time of error:

#Ecto.Changeset<
  action: :validate,
  changes: %{
    entry: %Acme.CaseContext.ProtocolEntry.Sms{
      delivery_receipt_id: nil,
      text: "f",
      uuid: nil
    },
    type: "sms"
  },
  errors: [],
  data: #Acme.CaseContext.ProtocolEntry<>,
  valid?: true
>

Changeset when working:

#Ecto.Changeset<
  action: :validate,
  changes: %{
    entry: #Ecto.Changeset<
      action: :insert,
      changes: %{text: "fffffffffffffffffffffffff"},
      errors: [delivery_receipt_id: {"can't be blank", [validation: :required]}],
      data: #Hygeia.CaseContext.ProtocolEntry.Sms<>,
      valid?: false
    >,
    type: "sms"
  },
  errors: [],
  data: #Hygeia.CaseContext.ProtocolEntry<>,
  valid?: false
>
mathieuprog commented 3 years ago

Thank you for reporting. There are tests for forms, and I use the library in my own project with forms; I personally didn't encounter any issue.

I'll have a look. If you have an idea of what scenario is missing from the tests, let me know!

maennchen commented 3 years ago

@mathieuprog Are you releasing this right away by any chance? (I need to fix it in my application and I'll either wait for the release or switch the dep to use git instead.)

mathieuprog commented 3 years ago

Just done:)