sonata-project / SonataDoctrineORMAdminBundle

Integrate Doctrine ORM into the SonataAdminBundle
https://docs.sonata-project.org/projects/SonataDoctrineORMAdminBundle
MIT License
445 stars 344 forks source link

Argument 1 passed to Sonata\AdminBundle\Form\DataTransformer\ModelToIdPropertyTransformer::__construct() must implement interface Sonata\AdminBundle\Model\ModelManagerInterface, null given #1041

Closed soullivaneuh closed 3 years ago

soullivaneuh commented 4 years ago

Environment

Sonata packages

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle              3.66.0 3.66.0 The missing Symfony Admin Generator
sonata-project/block-bundle              3.18.4 4.2.0  Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/core-bundle               3.18.0 3.18.0 Symfony SonataCoreBundle (abandoned)
sonata-project/datagrid-bundle           2.5.0  3.2.0  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.6.0  1.6.0  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.17.1 3.17.1 Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       2.5.0  2.5.0  Symfony SonataEasyExtendsBundle
sonata-project/exporter                  1.11.1 2.2.0  Lightweight Exporter library
sonata-project/intl-bundle               2.7.0  2.7.0  Symfony SonataIntlBundle

Symfony packages

$ composer show --latest 'symfony/*'
symfony/asset                      v4.4.8  v5.0.8  Symfony Asset Component
symfony/browser-kit                v4.4.8  v5.0.8  Symfony BrowserKit Component
symfony/cache                      v4.4.8  v5.0.8  Symfony Cache component with PSR-6, PSR-16, and tags
symfony/cache-contracts            v2.0.1  v2.0.1  Generic abstractions related to caching
symfony/config                     v4.4.8  v5.0.8  Symfony Config Component
symfony/console                    v4.4.8  v5.0.8  Symfony Console Component
symfony/contracts                  v1.1.0  v2.1.0  A set of abstractions extracted out of the Symfony components
symfony/css-selector               v5.0.8  v5.0.8  Symfony CssSelector Component
symfony/debug                      v4.4.8  v4.4.8  Symfony Debug Component
symfony/debug-bundle               v4.4.8  v5.0.8  Symfony DebugBundle
symfony/dependency-injection       v4.4.8  v5.0.8  Symfony DependencyInjection Component
symfony/doctrine-bridge            v4.4.8  v5.0.8  Symfony Doctrine Bridge
symfony/dom-crawler                v5.0.8  v5.0.8  Symfony DomCrawler Component
symfony/dotenv                     v4.4.8  v5.0.8  Registers environment variables from a .env file
symfony/error-handler              v4.4.8  v5.0.8  Symfony ErrorHandler Component
symfony/event-dispatcher           v4.4.8  v5.0.8  Symfony EventDispatcher Component
symfony/event-dispatcher-contracts v1.1.7  v2.0.1  Generic abstractions related to dispatching event
symfony/expression-language        v4.4.8  v5.0.8  Symfony ExpressionLanguage Component
symfony/filesystem                 v4.4.8  v5.0.8  Symfony Filesystem Component
symfony/finder                     v4.4.8  v5.0.8  Symfony Finder Component
symfony/flex                       v1.6.2  v1.6.2  Composer plugin for Symfony
symfony/form                       v4.4.8  v5.0.8  Symfony Form Component
symfony/framework-bundle           v4.4.8  v5.0.8  Symfony FrameworkBundle
symfony/http-foundation            v4.4.8  v5.0.8  Symfony HttpFoundation Component
symfony/http-kernel                v4.4.8  v5.0.8  Symfony HttpKernel Component
symfony/inflector                  v5.0.8  v5.0.8  Symfony Inflector Component
symfony/intl                       v4.4.8  v5.0.8  A PHP replacement layer for the C intl extension that includes additio...
symfony/lock                       v4.4.8  v5.0.8  Symfony Lock Component
symfony/mime                       v5.0.8  v5.0.8  A library to manipulate MIME messages
symfony/monolog-bridge             v5.0.8  v5.0.8  Symfony Monolog Bridge
symfony/monolog-bundle             v3.5.0  v3.5.0  Symfony MonologBundle
symfony/options-resolver           v4.4.8  v5.0.8  Symfony OptionsResolver Component
symfony/phpunit-bridge             v4.4.8  v5.0.8  Symfony PHPUnit Bridge
symfony/polyfill-ctype             v1.15.0 v1.15.0 Symfony polyfill for ctype functions
symfony/polyfill-iconv             v1.15.0 v1.15.0 Symfony polyfill for the Iconv extension
symfony/polyfill-intl-grapheme     v1.15.0 v1.15.0 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu          v1.15.0 v1.15.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn          v1.15.0 v1.15.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer   v1.15.0 v1.15.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring          v1.15.0 v1.15.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php56             v1.15.0 v1.15.0 Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php72             v1.15.0 v1.15.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73             v1.15.0 v1.15.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-util              v1.15.0 v1.15.0 Symfony utilities for portability of PHP codes
symfony/process                    v4.4.8  v5.0.8  Symfony Process Component
symfony/property-access            v4.4.8  v5.0.8  Symfony PropertyAccess Component
symfony/property-info              v4.4.8  v5.0.8  Symfony Property Info Component
symfony/proxy-manager-bridge       v4.4.8  v5.0.8  Symfony ProxyManager Bridge
symfony/psr-http-message-bridge    v1.3.0  v2.0.0  PSR HTTP message bridge
symfony/routing                    v4.4.8  v5.0.8  Symfony Routing Component
symfony/security                   v4.4.8  v4.4.8  Symfony Security Component
symfony/security-acl               v3.0.4  v3.0.4  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle            v4.4.8  v5.0.8  Symfony SecurityBundle
symfony/serializer                 v4.4.8  v5.0.8  Symfony Serializer Component
symfony/service-contracts          v2.0.1  v2.0.1  Generic abstractions related to writing services
symfony/stopwatch                  v4.4.8  v5.0.8  Symfony Stopwatch Component
symfony/string                     v5.0.8  v5.0.8  Symfony String component
symfony/swiftmailer-bundle         v3.4.0  v3.4.0  Symfony SwiftmailerBundle
symfony/templating                 v4.4.8  v5.0.8  Symfony Templating Component
symfony/translation                v4.4.8  v5.0.8  Symfony Translation Component
symfony/translation-contracts      v2.0.1  v2.0.1  Generic abstractions related to translation
symfony/twig-bridge                v4.4.8  v5.0.8  Symfony Twig Bridge
symfony/twig-bundle                v4.4.8  v5.0.8  Symfony TwigBundle
symfony/validator                  v4.4.8  v5.0.8  Symfony Validator Component
symfony/var-dumper                 v4.4.8  v5.0.8  Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter               v5.0.8  v5.0.8  A blend of var_export() + serialize() to turn any serializable data st...
symfony/web-link                   v4.4.8  v5.0.8  Symfony WebLink Component
symfony/web-profiler-bundle        v4.4.8  v5.0.8  Symfony WebProfilerBundle
symfony/webpack-encore-bundle      v1.7.3  v1.7.3  Integration with your Symfony app & Webpack Encore!
symfony/yaml                       v4.4.8  v5.0.8  Symfony Yaml Component

PHP version

$ php -v
PHP 7.3.15 (cli) (built: Feb 26 2020 12:46:49) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.15, Copyright (c) 1998-2018 Zend Technologies

Subject

After a composer update, moving from admin-bundle v3.51.0 to v3.66.0, I have a crash doing a global search:

Steps to reproduce

  1. Update to v3.66.0
  2. Use ModelAutocompleteType (see implement example)
protected function configureFormFields(FormMapper $formMapper): void
{
    $formMapper
        ->add('name')
        ->add('description')
        ->add('base', null, ['required' => false])
        ->add('packages', ModelAutocompleteType::class, [
            'property' => 'name',
            'multiple' => true,
            'required' => false,
        ])
    ;
}

Expected results

Working as before.

Actual results

Argument 1 passed to Sonata\AdminBundle\Form\DataTransformer\ModelToIdPropertyTransformer::__construct() must implement interface Sonata\AdminBundle\Model\ModelManagerInterface, null given, called in /app/vendor/php/sonata-project/admin-bundle/src/Form/Type/ModelAutocompleteType.php on line 39
soullivaneuh commented 4 years ago

It's look like the model_manager option is not automatically provided anymore. Before I have:

ModelManager {#5224 ▼
  #registry: Registry {#709 ▶}
  #cache: array:25 [▶]
}

No I have null.

Did a dump here:

class ModelAutocompleteType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        dump($options['model_manager']);
VincentLanglet commented 4 years ago

v3.51.0 to v3.66.0 is a big update @soullivaneuh.

Can you make smaller update in order to get the BC-break release ?

soullivaneuh commented 4 years ago

@VincentLanglet Maybe a big update, but it should BC as it is just minors. ;-)

I'm currently investigating, but I have nothing more to offer for now.

soullivaneuh commented 4 years ago

Well, if I put back only this bundle to its original version (3.51.0), I still have the error.

Looks like the issue come from somewhere else. Maybe core-bundle? Did you remember any change about dependency injection on the sonata ecosystem?

soullivaneuh commented 4 years ago

Found the faulty one: sonata-project/doctrine-orm-admin-bundle

Rolling back from 3.14.0 to 3.11.0 resolve the issue. Start bisecting.

soullivaneuh commented 4 years ago

Issue happens starting 3.13.0.

soullivaneuh commented 4 years ago

After bisecting, it appears the bug was introduced in 3bef7482ae58f0cd1e858d28516bbe6e62c67d13, related to #945

soullivaneuh commented 4 years ago

Ok found why: I was sill using doctrine_orm_model_autocomplete somewhere and this type is not supported anymore. Here is my code fix:

❯ gd src/         
diff --git a/src/Admin/Extension/AutoFieldsAdminExtension.php b/src/Admin/Extension/AutoFieldsAdminExtension.php
index b0f1f1029..2f9fc110c 100644
--- a/src/Admin/Extension/AutoFieldsAdminExtension.php
+++ b/src/Admin/Extension/AutoFieldsAdminExtension.php
@@ -17,6 +17,7 @@ use Doctrine\ORM\Mapping\ClassMetadata;
 use Sonata\AdminBundle\Admin\AbstractAdminExtension;
 use Sonata\AdminBundle\Datagrid\DatagridMapper;
 use Sonata\AdminBundle\Datagrid\ListMapper;
 use Sonata\AdminBundle\Show\ShowMapper;
+use Sonata\DoctrineORMAdminBundle\Filter\ModelAutocompleteFilter;
 use Symfony\Bridge\Doctrine\RegistryInterface;
 use Webmozart\Assert\Assert;
@@ -57,7 +58,7 @@ final class AutoFieldsAdminExtension extends AbstractAdminExtension
             }

             if ($targetEntity === Hosting::class) {
-                $datagridMapper->add($fieldName, 'doctrine_orm_model_autocomplete', [], null, [
+                $datagridMapper->add($fieldName, ModelAutocompleteFilter::class, [], null, [
                     'property' => 'name',
                 ]);
             }

Introduced here: https://github.com/sonata-project/SonataDoctrineORMAdminBundle/commit/3bef7482ae58f0cd1e858d28516bbe6e62c67d13#diff-eeb9e64780aabe9b2d7d6de3f0522447R159

To me, even if dropping version support is BC, making code not working anymore is not.

The old syntax should be still supported until a new major is coming.

I let you decide of what to do now.

VincentLanglet commented 4 years ago

Introduced back here: https://github.com/sonata-project/SonataDoctrineORMAdminBundle/commit/5ede9a3239510249af997b65d6ab328551694934#diff-7d465efca2ece4545e7c9e9072a77b27

Removed again here: https://github.com/sonata-project/SonataDoctrineORMAdminBundle/commit/3bef7482ae58f0cd1e858d28516bbe6e62c67d13#diff-eeb9e64780aabe9b2d7d6de3f0522447R159

Do you mind making the PR @soullivaneuh and modifying the NEXT_MAJOR comment which lead to the mistake ?

franmomu commented 4 years ago

Sure! I think so too, in fact @core23 pointed me that out and I re-added them back in https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/945/commits/cdaae029279d237330ea730b95afbdafb93f86aa, but I missed the one in DatagridBuilder.php.

To me, they should been added.

soullivaneuh commented 4 years ago

I let the PR work for anybody who wants to, I do not have enough time to allow sorry.

github-actions[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.