Repository navigation
Conversation
16d7b24 to
ed3e4fa
Compare
|
This PR seems to fix some of the immediate form validation problems I was having (even though the issue you were mentioning this PR in (#113) is about There seems to be one failing test though I am not sure why this is happening though, as right now I didn't dive deep enough into phoenix form handling yet. Maybe it is happening because recent changes in phoenix html/form handling? Furthermore, you mentioned in #113 that there were issues with the sort params as well, specifically with the approach taken in this PR. Did you find some time to have another look at this yet @nduitz ? |
|
Hey there, One thing I noticed yesterday which caused me a lot of headaches was that |
Never mind my comment about |
|
I would love for this to be merged as we just ran into this today and are jumping through hoops to get around it. |
|
@coladarci @nduitz it is currently in Draft status and it has conflicts. Can anyone resolve and test this? |
|
My fix was off latest release but it appears master is pretty far ahead? I'll investigate how to apply my fix to latest master and open a new PR as a backup.. thanks for the reply! I love this library and find myself going to it in project after project! |
|
I am actually running another commit in prod right now that fixed all of my issues. Good thing is, I implemented tests for all problems I encountered. I will have a look at it next week, checkout the latest main, apply the tests and see if I can reproduce the issues and fix them again. |
ed3e4fa to
0459585
Compare
|
Nevermind, could do it now. 2fcfcbe and 0bd61b5 apply the fixes of the original PR But I can't remember in which cases. I could investigate more and create a minimal reproduction repo if you want. But that would take some time :) |
0459585 to
ee6d450
Compare
|
Thanks @nduitz !! Yeah I had issues with deeply embedded changesets being nuked. |
…within a <.polymorphic_embed_inputs_for /> (see mathieuprog#115 and mathieuprog#132 on upstream)
ee6d450 to
fb46fe6
Compare
|
With #115 now being merged, this only two commits could be dropped from this. I didn't realize I had another PR open actually :D It's been a while. Sorry for that |
|
I asked ChatGPT 5.4 xthink for a review and it says:
wdyt? |
|
Added the failing test |
|
Thanks :) I will have a look at the implementation |
failing test: expect errors for polymorphic inputs
f4843b6 to
631fcd8
Compare
|
Hey, sorry this took me a while. I actually made the wrong assumption in the test, which led to me introducing another bug :D I changed the intial assumption (fix up commit) and added an fix for the bug I introduced :) |
|
Added failing tests. ChatGPT said:
In other words:
In other words: Finding 1 is not a regression, but it is still an incomplete fix. On the base commit, the same repro already suppresses child errors for a prebuilt invalid child changeset under a parent with action: :insert. In /private/tmp/polph-132-base, to_form/4 produced form_action: :insert and form_errors: [] for that setup. The PR changes the internal failure mode in helpers.ex (line 116): before, the helper effectively erased the child errors from f.source; now it preserves them on f.source.errors but still fails to promote the child action, so f.errors stays empty. So the bug is real, but it is not newly introduced by this PR. It is better described as “the new %Ecto.Changeset{} path still does not complete the parent-action fix.” Finding 2 is also not a regression. The bad :many params behavior already exists on the base commit, and the relevant extraction line is unchanged: head helpers (line 56) matches base helpers (line 56). Running the same sorted string-keyed params repro on the base commit produced the same result as head: sorted row structs were correct, but row params came back as [%{"0" => ..., "1" => ...}, %{}] instead of one params map per row. So this is a pre-existing bug that the PR still does not fix. |
|
sorry to throw that at you like that btw lol |
|
That's alright, thank you. I hadn't much time lately to look at this. I'll try and get back to you in the near future 🙂 |
|
The near future is now :D What I did:
|
A valid child form has no changes, so phoenix_ecto read nested embed values from the raw form parameters. Drop embed keys from the form parameters and keep them on the changeset for nested polymorphic forms.
The changes of PR mathieuprog#132, in one commit: - After the cast, changeset.params holds the params of each child for the field. For a list of embeds, it is a list in the order of the cast, without dropped and ignored rows. The README describes this. - Each child form of a list gets the params of its own row. Before, the first form got the params of all rows, so _persistent_id and other row values were lost. - form.data of a child form is the data of the child, not a changeset. - A child form takes the action of the parent form. A parent without an action hides the errors of the children, and a parent with an action shows them, also for a child changeset without an action. test/polymorphic_embed/html/helpers_test.exs holds regression tests for these cases.
This fixes two things:
a) It picks up the correct action (not from the changeset but from the parent form)
b) It fixes handling parameters for cardinality :many
If you remove the first commit you will see the test is failing and it will produce the incorrect form.
Instead of generating two forms per polymorphic type it will generate only one form for the
devicetype