{"action":"created","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/8527","labels_url":"https://api.github.com/repos/symfony/symfony/issues/8527/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/8527/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/8527/events","html_url":"https://github.com/symfony/symfony/issues/8527","id":16991948,"number":8527,"title":"[2.3][Form][Collection] - Regression causing an UnexpectedTypeException","user":{"login":"aesh-taregh","id":4860337,"avatar_url":"https://avatars.githubusercontent.com/u/4860337?v=3","gravatar_id":"","url":"https://api.github.com/users/aesh-taregh","html_url":"https://github.com/aesh-taregh","followers_url":"https://api.github.com/users/aesh-taregh/followers","following_url":"https://api.github.com/users/aesh-taregh/following{/other_user}","gists_url":"https://api.github.com/users/aesh-taregh/gists{/gist_id}","starred_url":"https://api.github.com/users/aesh-taregh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aesh-taregh/subscriptions","organizations_url":"https://api.github.com/users/aesh-taregh/orgs","repos_url":"https://api.github.com/users/aesh-taregh/repos","events_url":"https://api.github.com/users/aesh-taregh/events{/privacy}","received_events_url":"https://api.github.com/users/aesh-taregh/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/symfony/symfony/labels/Form","name":"Form","color":"DDDDDD"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2013-07-19T20:43:44Z","updated_at":"2015-03-10T10:45:07Z","closed_at":"2014-01-04T07:03:21Z","body":"In my web application I commonly use the pattern of mapping a collection of fields to an array on one of my entities.  As of upgrading to 2.3 today I've noticed that if a collection has only one field and that is empty, then an UnexpectedTypeException is thrown on line 76 of EventListener/ResizeFormListener.php.  I tried adding an empty_data option of either null or array to both the collections and the field, but an empty string was still returned.\r\n\r\nAlso, the data is being posted as an array `application[person][citizenship][countries][0]`, which class would be squishing this down to a string?\r\n\r\nThis is an example of one of my collections, here the aaws field is just a choice that gets its values from a webservice.\r\n\r\n```php\r\n$builder->add('countries', 'collection', array('type' => 'aaws', 'options' => array(\r\n                                                                 'label' => 'Citizenship Country', \r\n                                                                 'app_data_attr' => 'countries', \r\n                                                                 'empty_value' => 'Choose an option',\r\n                                                                 'empty_data'  => null,\r\n                                                                 'required' => false,\r\n                                                                 'preferred_choices' => array('USA'),\r\n                                                                 'attr' => array('class' => 'gfu-required-field')\r\n                                                                  ),\r\n                                                                 'allow_add' => true,\r\n                                                                 'allow_delete' => true,\r\n                                                                 'prototype' => true,\r\n                                                                 'error_bubbling' => false,\r\n                                                                 'empty_data' => null,\r\n                                                  )\r\n\r\n```\r\n\r\nHere is the plain text of my stack trace\r\n```\r\n[1] Symfony\\Component\\Form\\Exception\\UnexpectedTypeException: Expected argument of type \"array or (\\Traversable and \\ArrayAccess)\", \"string\" given\r\n    at n/a\r\n        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php line 76\r\n\r\n    at Symfony\\Component\\Form\\Extension\\Core\\EventListener\\ResizeFormListener->preSetData(object(FormEvent))\r\n        in  line \r\n\r\n    at call_user_func(array(object(ResizeFormListener), 'preSetData'), object(FormEvent))\r\n        in /vagrant/app/cache/dev/classes.php line 1676\r\n\r\n    at Symfony\\Component\\EventDispatcher\\EventDispatcher->doDispatch(array(array(object(ResizeFormListener), 'preSetData')), 'form.pre_set_data', object(FormEvent))\r\n        in /vagrant/app/cache/dev/classes.php line 1609\r\n\r\n    at Symfony\\Component\\EventDispatcher\\EventDispatcher->dispatch('form.pre_set_data', object(FormEvent))\r\n        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php line 42\r\n\r\n    at Symfony\\Component\\EventDispatcher\\ImmutableEventDispatcher->dispatch('form.pre_set_data', object(FormEvent))\r\n        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 321\r\n\r\n    at Symfony\\Component\\Form\\Form->setData('')\r\n        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php line 59\r\n\r\n    at Symfony\\Component\\Form\\Extension\\Core\\DataMapper\\PropertyPathMapper->mapDataToForms(object(Ethnicity), object(RecursiveIteratorIterator))\r\n        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 375\r\n\r\n    at Symfony\\Component\\Form\\Form->setData(object(Ethnicity))\r\n        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php line 59\r\n\r\n    at Symfony\\Component\\Form\\Extension\\Core\\DataMapper\\PropertyPathMapper->mapDataToForms(object(Person), object(RecursiveIteratorIterator))\r\n        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 375\r\n\r\n    at Symfony\\Component\\Form\\Form->setData(object(Person))\r\n        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php line 59\r\n\r\n    at Symfony\\Component\\Form\\Extension\\Core\\DataMapper\\PropertyPathMapper->mapDataToForms(object(Application), object(RecursiveIteratorIterator))\r\n        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 375\r\n\r\n    at Symfony\\Component\\Form\\Form->setData(object(Application))\r\n        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 467\r\n\r\n    at Symfony\\Component\\Form\\Form->initialize()\r\n        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 229\r\n\r\n    at Symfony\\Component\\Form\\FormBuilder->getForm()\r\n        in /vagrant/vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php line 39\r\n\r\n    at Symfony\\Component\\Form\\FormFactory->create(object(ApplicationType), object(Application), array('validation_groups' => array('Default'), 'gfu_submit' => false))\r\n        in /vagrant/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php line 163\r\n\r\n    at Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller->createForm(object(ApplicationType), object(Application), array('validation_groups' => array('Default'), 'gfu_submit' => false))\r\n        in /vagrant/src/Gfu/AppBundle/Controller/AppController.php line 472\r\n\r\n    at Gfu\\AppBundle\\Controller\\AppController->editAction('72', object(Request))\r\n        in  line \r\n\r\n    at call_user_func_array(array(object(AppController), 'editAction'), array('72', object(Request)))\r\n        in /vagrant/app/bootstrap.php.cache line 2774\r\n\r\n    at Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw(object(Request), '1')\r\n        in /vagrant/app/bootstrap.php.cache line 2748\r\n\r\n    at Symfony\\Component\\HttpKernel\\HttpKernel->handle(object(Request), '1', true)\r\n        in /vagrant/app/bootstrap.php.cache line 2878\r\n\r\n    at Symfony\\Component\\HttpKernel\\DependencyInjection\\ContainerAwareHttpKernel->handle(object(Request), '1', true)\r\n        in /vagrant/app/bootstrap.php.cache line 2179\r\n\r\n    at Symfony\\Component\\HttpKernel\\Kernel->handle(object(Request))\r\n        in /vagrant/web/app_dev.php line 28\r\n```"},"comment":{"url":"https://api.github.com/repos/symfony/symfony/issues/comments/78030761","html_url":"https://github.com/symfony/symfony/issues/8527#issuecomment-78030761","issue_url":"https://api.github.com/repos/symfony/symfony/issues/8527","id":78030761,"user":{"login":"jakzal","id":190447,"avatar_url":"https://avatars.githubusercontent.com/u/190447?v=3","gravatar_id":"","url":"https://api.github.com/users/jakzal","html_url":"https://github.com/jakzal","followers_url":"https://api.github.com/users/jakzal/followers","following_url":"https://api.github.com/users/jakzal/following{/other_user}","gists_url":"https://api.github.com/users/jakzal/gists{/gist_id}","starred_url":"https://api.github.com/users/jakzal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jakzal/subscriptions","organizations_url":"https://api.github.com/users/jakzal/orgs","repos_url":"https://api.github.com/users/jakzal/repos","events_url":"https://api.github.com/users/jakzal/events{/privacy}","received_events_url":"https://api.github.com/users/jakzal/received_events","type":"User","site_admin":false},"created_at":"2015-03-10T10:45:07Z","updated_at":"2015-03-10T10:45:07Z","body":"@teu in which case this would be a duplicate of #13804. There's already a PR with a fix #13851."}}