Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Form] Errors Property Paths mismatch CollectionType children when removing an entry#39438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@cristoforocervino
Copy link
Contributor

@cristoforocervinocristoforocervino commentedDec 10, 2020
edited by OskarStark
Loading

QA
Branch?7.1
Bug fix?no
New feature?yes
Deprecations?no
Tickets-
LicenseMIT
Doc PR-

Description
When you remove an entry fromCollectionType and you have errors on children, errors property paths generated byValidatorExtension are matching final object collection indexes but do not match From children entries index/names.

How to reproduce
Unit test provided.

Solution
Introduce new feature withkeep_as_list (boolean default tofalse) option to reindex children on submit.

andimg93 reacted with eyes emoji
@carsonbot
Copy link

Hey!

I didn't know that was capable of this emotion. I really really like reviewing this PR. Well done.

To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done?

Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review.

Cheers!

Carsonbot

@cristoforocervinocristoforocervino marked this pull request as ready for reviewDecember 10, 2020 19:15
@carsonbotcarsonbot added this to the4.4 milestoneDec 10, 2020
@cristoforocervinocristoforocervinoforce-pushed theform-collection-type-errors-property-paths-mismatch branch froma435596 todc5e0b2CompareDecember 10, 2020 19:16
@xabbuh
Copy link
Member

@StevioStudio Sorry, your PR somehow slipped through. Thank you for taking the time to create a failing test case. That's really appreciated. 👍 I will try to look into a possible fix soon.

cristoforocervino reacted with thumbs up emoji

@xabbuh
Copy link
Member

As your test also asserts the entry form types of the collection type are not renamed. So after submitting we only have entry types named0,2, and3. However, due to howremoveAuthor() is implemented the submitted data is mapped to an indexed array. Thus when the form is displayed again, we now have data indexed with0,1, and2 while the form still has0,2,3.

With the current implementation I do not see how we can actually fix this as inside theResizeFormListener we do not know whether or not the index is important.

For your project I see two possible workarounds:

  • Change the implementation in your model class to not reindex the collection when the form data is mapped back (which might not be suitable depending on how you deal with the data).
  • Register a custom event listener that runs after the built-inResizeFormListener and changes the form names.

@cristoforocervino
Copy link
ContributorAuthor

For your project I see two possible workarounds:

  • Change the implementation in your model class to not reindex the collection when the form data is mapped back (which might not be suitable depending on how you deal with the data).
  • Register a custom event listener that runs after the built-inResizeFormListener and changes the form names.

Wait, this is not only related to the model I'm using in this unit test.
CollectionType is usually used with Doctrine Collections. Doctrine collectionsremoveElement method also reindex the collection the same way. Shouldn't Symfony Form at least provide an option to handle this (common) situation?

@xabbuh
Copy link
Member

While I agree I don't see a way to fix this without introducing a new option (like proposed in#7828). So that would go into a future minor version instead of a patch release.

By the way, is it really a common use case to use theCollectionType with Doctrine entities? What are the use case where theEntityType isn't sufficient?

@cristoforocervino
Copy link
ContributorAuthor

cristoforocervino commentedJan 17, 2021
edited
Loading

Well, you know thatCollectionType andEntityType are meant to handle completely different situations.
I do not have numbers or statistics to show you, but it's pretty common, for example, to have aCollectionType with the optionentry_type set toEntityType.

I think the new option with a minor version release could be a good idea.
Like asequential_keys option set tofalse by default.
Ifsequential_keys is set totrue,ResizeFormListener is going to handle a situation like the one described by my unit test in the right way.

What do you think?

andimg93 reacted with thumbs up emoji

@xabbuh
Copy link
Member

I have a feature like that on my to-do list. Though not sure when I will find the time for it. Hopefully it will make it to 5.3.

cristoforocervino reacted with thumbs up emoji

@cristoforocervinocristoforocervinoforce-pushed theform-collection-type-errors-property-paths-mismatch branch from88d307e toa4462c8CompareJanuary 18, 2021 20:30
@cristoforocervino
Copy link
ContributorAuthor

I came up with a newreindex_on_submit boolean option set tofalse by default.
I updated code and test. What do you think? Did you have in mind something different?

@cristoforocervinocristoforocervinoforce-pushed theform-collection-type-errors-property-paths-mismatch branch froma4462c8 to2cad8eeCompareApril 13, 2021 18:16
@cristoforocervinocristoforocervino changed the base branch from4.4 to5.xApril 13, 2021 18:18
@cristoforocervino
Copy link
ContributorAuthor

This PR initially started as a bug fix with unit test provided to explain the issue.
I changed it into a new feature by introducing a newkeep_as_list option forCollectionType.
I'm still open to suggestions on how to improve this code and find the right way to solve the highlighted issue.

@fabpotfabpot modified the milestones:4.4,5.4Aug 26, 2021
@fabpotfabpot modified the milestones:5.4,6.1Oct 30, 2021
@andimg93
Copy link

@xabbuh,@yceruto,@chalasr,@dunglas,@jderusse,@lyrixx,@sroze,@wouterj
Please look into that issue fix, there are so many issues that all trace back to this bug and have been around since 2013 - it's really important, even if it's annoying to ask for focus here. Without a solution collections are simply not decently usable, it can and must not be a solution to re-index it all via javascript (frontend). Simply that you can't find a nice solution here (frontend based), but have to search out the individual parts via regex.

The real solution must be in the backend, because it is simply a bug and not a feature.

cristoforocervino, Nicolai6120, wmatex, and scroach reacted with thumbs up emoji

@fabpotfabpot modified the milestones:6.1,6.2May 20, 2022
@nicolas-grekasnicolas-grekas modified the milestones:6.2,6.3Nov 5, 2022
@nicolas-grekasnicolas-grekas modified the milestones:6.3,6.4May 23, 2023
@nicolas-grekasnicolas-grekas modified the milestones:6.4,7.1Nov 15, 2023
Copy link
Contributor

@HeahDudeHeahDude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm not against a new opt-in feature for this but we should be careful when documenting it.
Indeed, such behavior depends on how the collection type data is mapped to the parent object.
In other words, how the adder and remover are implemented in the holder of the collection impact indexes without being able to send feedback to the collection type when going back to the view with errors.
Sadly after discussing this issue with@stof, we cannot think of another way to work around that efficiently, since the PropertyAccess does not allow to set specific indexes when calling adders and removers.

//In fact, root form should NOT contain errors but it does
$this->assertCount(1,$form->getErrors(false));

//Let's do this again, but with "keep_as_list" option set to true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can you create another test method instead of grouping two tests in the same one please?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We also need a rebase and to update the changelog.
Please tell us if you want to do it or if we should take over, thank you.

@cristoforocervinocristoforocervinoforce-pushed theform-collection-type-errors-property-paths-mismatch branch from94bae4d to70e1b0eCompareDecember 9, 2023 11:53
@OskarStarkOskarStark modified the milestones:6.4,7.1Dec 9, 2023
@OskarStarkOskarStark added Feature and removed Bug labelsDec 9, 2023
@cristoforocervinocristoforocervinoforce-pushed theform-collection-type-errors-property-paths-mismatch branch from70e1b0e tofff25e3CompareDecember 9, 2023 12:34
Copy link
Contributor

@HeahDudeHeahDude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We need to make fabbot happy fixing the CS and update the Form component CHANGELOG please. Thanks

cristoforocervino reacted with thumbs up emoji
@cristoforocervinocristoforocervinoforce-pushed theform-collection-type-errors-property-paths-mismatch branch fromfff25e3 tof31de2bCompareDecember 9, 2023 13:18
@fabpotfabpotforce-pushed theform-collection-type-errors-property-paths-mismatch branch fromf31de2b to39587cbCompareDecember 9, 2023 14:28
@fabpot
Copy link
Member

Thank you@cristoforocervino.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@xabbuhxabbuhAwaiting requested review from xabbuhxabbuh is a code owner

@ycerutoycerutoAwaiting requested review from ycerutoyceruto is a code owner

@chalasrchalasrAwaiting requested review from chalasr

@dunglasdunglasAwaiting requested review from dunglas

@jderussejderusseAwaiting requested review from jderusse

@lyrixxlyrixxAwaiting requested review from lyrixx

@srozesrozeAwaiting requested review from sroze

@wouterjwouterjAwaiting requested review from wouterj

+1 more reviewer

@HeahDudeHeahDudeHeahDude approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

7.1

Development

Successfully merging this pull request may close these issues.

8 participants

@cristoforocervino@carsonbot@xabbuh@andimg93@fabpot@HeahDude@nicolas-grekas@OskarStark

[8]ページ先頭

©2009-2025 Movatter.jp