Sonataadminbundle: appendformfield error child _delete does not exist

Created on 27 Feb 2019  路  12Comments  路  Source: sonata-project/SonataAdminBundle

Environment

Sonata packages

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle              3.45.2 3.45.2 The missing Symfony Admin Generator
sonata-project/block-bundle              3.14.0 3.14.0 Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/core-bundle               3.16.1 3.16.1 Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.4.0  2.4.0  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.1.5  1.1.5  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.8.2  3.8.2  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  2.0.1  2.0.1  Lightweight Exporter library

Symfony packages

$ composer show --latest 'symfony/*'
symfony/asset                v4.2.3  v4.2.3  Symfony Asset Component
symfony/browser-kit          v4.2.3  v4.2.3  Symfony BrowserKit Component
symfony/cache                v4.2.3  v4.2.3  Symfony Cache component with PSR-6, PSR-16, and tags
symfony/config               v4.2.3  v4.2.3  Symfony Config Component
symfony/console              v4.2.3  v4.2.3  Symfony Console Component
symfony/contracts            v1.0.2  v1.0.2  A set of abstractions extracted out of the Symfony components
symfony/css-selector         v4.2.3  v4.2.3  Symfony CssSelector Component
symfony/debug                v4.2.3  v4.2.3  Symfony Debug Component
symfony/debug-bundle         v4.2.3  v4.2.3  Symfony DebugBundle
symfony/debug-pack           v1.0.7  v1.0.7  A debug pack for Symfony projects
symfony/dependency-injection v4.2.3  v4.2.3  Symfony DependencyInjection Component
symfony/doctrine-bridge      v4.2.3  v4.2.3  Symfony Doctrine Bridge
symfony/dom-crawler          v4.2.3  v4.2.3  Symfony DomCrawler Component
symfony/dotenv               v4.2.3  v4.2.3  Registers environment variables from a .env file
symfony/event-dispatcher     v4.2.3  v4.2.3  Symfony EventDispatcher Component
symfony/expression-language  v4.2.3  v4.2.3  Symfony ExpressionLanguage Component
symfony/filesystem           v4.2.3  v4.2.3  Symfony Filesystem Component
symfony/finder               v4.2.3  v4.2.3  Symfony Finder Component
symfony/flex                 v1.2.0  v1.2.0  Composer plugin for Symfony
symfony/form                 v4.2.3  v4.2.3  Symfony Form Component
symfony/framework-bundle     v4.2.3  v4.2.3  Symfony FrameworkBundle
symfony/http-foundation      v4.2.3  v4.2.3  Symfony HttpFoundation Component
symfony/http-kernel          v4.2.3  v4.2.3  Symfony HttpKernel Component
symfony/inflector            v4.2.3  v4.2.3  Symfony Inflector Component
symfony/intl                 v4.2.3  v4.2.3  A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/maker-bundle         v1.11.3 v1.11.3 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget ab...
symfony/monolog-bridge       v4.2.3  v4.2.3  Symfony Monolog Bridge
symfony/monolog-bundle       v3.3.1  v3.3.1  Symfony MonologBundle
symfony/options-resolver     v4.2.3  v4.2.3  Symfony OptionsResolver Component
symfony/orm-pack             v1.0.6  v1.0.6  A pack for the Doctrine ORM
symfony/phpunit-bridge       v4.2.3  v4.2.3  Symfony PHPUnit Bridge
symfony/polyfill-ctype       v1.10.0 v1.10.0 Symfony polyfill for ctype functions
symfony/polyfill-intl-icu    v1.10.0 v1.10.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring    v1.10.0 v1.10.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72       v1.10.0 v1.10.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/process              v4.2.3  v4.2.3  Symfony Process Component
symfony/profiler-pack        v1.0.4  v1.0.4  A pack for the Symfony web profiler
symfony/property-access      v4.2.3  v4.2.3  Symfony PropertyAccess Component
symfony/property-info        v4.2.3  v4.2.3  Symfony Property Info Component
symfony/routing              v4.2.3  v4.2.3  Symfony Routing Component
symfony/security-acl         v3.0.1  v3.0.1  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle      v4.2.3  v4.2.3  Symfony SecurityBundle
symfony/security-core        v4.2.3  v4.2.3  Symfony Security Component - Core Library
symfony/security-csrf        v4.2.3  v4.2.3  Symfony Security Component - CSRF Library
symfony/security-guard       v4.2.3  v4.2.3  Symfony Security Component - Guard
symfony/security-http        v4.2.3  v4.2.3  Symfony Security Component - HTTP Integration
symfony/serializer           v4.2.3  v4.2.3  Symfony Serializer Component
symfony/serializer-pack      v1.0.2  v1.0.2  A pack for the Symfony serializer
symfony/stopwatch            v4.2.3  v4.2.3  Symfony Stopwatch Component
symfony/swiftmailer-bundle   v3.2.5  v3.2.5  Symfony SwiftmailerBundle
symfony/templating           v4.2.3  v4.2.3  Symfony Templating Component
symfony/translation          v4.2.3  v4.2.3  Symfony Translation Component
symfony/twig-bridge          v4.2.3  v4.2.3  Symfony Twig Bridge
symfony/twig-bundle          v4.2.3  v4.2.3  Symfony TwigBundle
symfony/validator            v4.2.3  v4.2.3  Symfony Validator Component
symfony/var-dumper           v4.2.3  v4.2.3  Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter         v4.2.3  v4.2.3  A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/web-link             v4.2.3  v4.2.3  Symfony WebLink Component
symfony/web-profiler-bundle  v4.2.3  v4.2.3  Symfony WebProfilerBundle
symfony/webpack-encore-pack  v1.0.3  v1.0.3  A pack for Symfony Encore
symfony/workflow             v4.2.3  v4.2.3  Symfony Workflow Component
symfony/yaml                 v4.2.3  v4.2.3  Symfony Yaml Component

PHP version

 $ php -v
PHP 7.2.15 (cli) (built: Feb  9 2019 03:10:54) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.15, Copyright (c) 1999-2018, by Zend Technologies

Subject

commit c7ca519dddf51d676b70801e0a7ed7d1a8d5beb1 introduced a bug in my project.
https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Admin/AdminHelper.php#L203

for a collection form field with

'type_options' => [
    'delete' => false,
],

when you click add on the collection you get 麓Child "_delete" does not exist.麓

Symfony\Component\Form\Exception\OutOfBoundsException:
Child "_delete" does not exist.

  at vendor/symfony/form/Form.php:946
  at Symfony\Component\Form\Form->get('_delete')
     (vendor/sonata-project/admin-bundle/src/Admin/AdminHelper.php:203)
  at Sonata\AdminBundle\Admin\AdminHelper->appendFormFieldElement(object(ProjectContactAdmin), object(ProjectContact), 'selion_project_contact_contactAttempts')
     (vendor/sonata-project/admin-bundle/src/Action/AppendFormFieldElementAction.php:84)
  at Sonata\AdminBundle\Action\AppendFormFieldElementAction->__invoke(object(Request))
     (vendor/symfony/http-kernel/HttpKernel.php:150)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:67)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:198)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (public/index.php:37)

fix

```
if ($childField->has('_delete')) {
$childField->get('_delete')->setData(isset($toDelete[$i]) && $toDelete[$i]);
++$i;
}
麓麓麓

bug unconfirmed

Most helpful comment

Hello everybody,

To fix that issue until Sonata team approve the PR you can use the PR #5532 as a patch (to avoid using a fork) . You must setup the "cweagans/composer-patches" package into your project to use the next configuration in composer:

    "extra": {
        "patches": {
            "sonata-project/admin-bundle": {
                "Fix 'Child _delete does not exist' #5483": "https://patch-diff.githubusercontent.com/raw/sonata-project/SonataAdminBundle/pull/5532.patch"
            }
        }
    }

All 12 comments

I had the same problem and your solution fixed it.

Thanks, it fixed the problem on my side too !!

Same

I used a composer patch now, working good so far. Had to update due to another bug :D.

+1
sonata-project/admin-bundle: 3.48.0

3.48.1 same problem

@sad270 any chance you can help with this? cc @sonata-project/contributors should we consider reverting it?

To fix this issue, add a value existence check on line 203 of AdminHelper:
image

@SerafimArts are you able to provide a PR?

@kunicmarko20
1) I do not have tests that would check specifically this problem.
2) I'm not sure that this fully corrects the error, because conducted manual testing without debugging

If this option suits, then there are no problems

Hello everybody,

To fix that issue until Sonata team approve the PR you can use the PR #5532 as a patch (to avoid using a fork) . You must setup the "cweagans/composer-patches" package into your project to use the next configuration in composer:

    "extra": {
        "patches": {
            "sonata-project/admin-bundle": {
                "Fix 'Child _delete does not exist' #5483": "https://patch-diff.githubusercontent.com/raw/sonata-project/SonataAdminBundle/pull/5532.patch"
            }
        }
    }

Ugly hack that solved the problem: in Admin class configureFormFields method
`

$formMapper

.....

    ->add('_delete', HiddenType::class, ['mapped' => false, 'required' => false])

    ->end();

`

Was this page helpful?
0 / 5 - 0 ratings