mathieuprog / polymorphic_embed

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

`traverse_errors/2` blows up when the polymorphic embed is valid #48

Closed jerelmiller closed 2 years ago

jerelmiller commented 2 years ago

Hey there! Thanks so much for this library! I've found great value in it!

I am using PolymorphicEmbed.traverse_errors/2 as a replacement for Ecto.Changeset.traverse_errors/2 and noticed that the function blows on a FunctionClauseError if the polymorphic embed is valid. I see that if the embedded changeset is valid, it applies the changes, which results in that field converted from a changeset to a struct. When traversing errors, it appears that when merging the polymorphic keys, it attempts to call traverse_errors/2 again, but since the change is now a struct instead of a changeset, traverse_errors/2 can't match, resulting in a FunctionClauseError.

mathieuprog commented 2 years ago

Hello, it's pretty clear:) first thing to do is to add a failing test. I'll work on that when I have time in the next few days, feel free to add one if you have time, otherwise I'll be on it some time later. Once we have a failing test, it will be solved pretty much immediately.

jerelmiller commented 2 years ago

Perfect! Hopefully I get some free time tomorrow to help out here! Thanks for getting back so quick!

mathieuprog commented 2 years ago

Fixed in PR https://github.com/mathieuprog/polymorphic_embed/pull/50