sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

For OneToMany, there is some concurrency between the form submission and row deletion #6391

Closed VincentLanglet closed 3 years ago

VincentLanglet commented 4 years ago

Environment

Sonata packages

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle              3.75.0 3.75.0 The missing Symfony Admin Generator
sonata-project/block-bundle              4.3.0  4.3.0  Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/doctrine-extensions       1.9.1  1.9.1  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.21.0 3.23.0 Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  2.3.0  2.3.0  Lightweight Exporter library
sonata-project/form-extensions           1.6.0  1.6.0  Symfony form extensions
sonata-project/twig-extensions           1.4.1  1.4.1  Sonata twig extensions

Subject

image

When using a oneToMany, if you delete a line, fields are not required anymore. But when I submit this form, I get an error because the form is trying to set the null BEFORE removing the entity ; and my setter doesn't accept null.

kirya-dev commented 4 years ago

Maybe need no process entity if them will be deleted?

VincentLanglet commented 4 years ago

Maybe need no process entity if them will be deleted?

If you have any idea about how, and wanna make try. I'll be happy to see how you would implement it

kirya-dev commented 4 years ago

Bug in appending (see ResizeFormListener::preSubmit) to removed in one event. And actually remove in other (see ResizeFormListener::OnSubmit).

Set null occurs between dispatch this events here: https://github.com/symfony/symfony/blob/b3a1851d43617c88aff68948554b0398fcdab07e/src/Symfony/Component/Form/Form.php#L620-L643

Detalied error description: 1) Method Form::submit dispatches PRE_SUBMIT on line 555. (ResizeFormListener adds item to removed) 2) Method Form::submit trying set data on line 628. 3) Method Form::submit dispatches SUBMIT on line 641. (ResizeFormListener do remove)

In think that right solution is: a) Do remove in PRE_SET_DATA. b) Delete removed property and other foo code.

kirya-dev commented 4 years ago

Same problem in symfony component: Remove data in onSubmit (): Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener

https://github.com/symfony/symfony/blob/b3a1851d43617c88aff68948554b0398fcdab07e/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php

VincentLanglet commented 4 years ago

Same problem in symfony component: Remove data in onSubmit (): Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener

https://github.com/symfony/symfony/blob/b3a1851d43617c88aff68948554b0398fcdab07e/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php

Maybe this issue could be created on Symfony repository then. You could provide a way to reproduce it.

VincentLanglet commented 3 years ago

Duplicate of https://github.com/sonata-project/SonataAdminBundle/issues/4348