sonata-project / SonataUserBundle

Symfony SonataUserBundle
https://docs.sonata-project.org/projects/SonataUserBundle
MIT License
342 stars 487 forks source link

Upgrading causes Model class "My\User" does not correspond to manager type "orm" #1403

Closed Bilge closed 3 years ago

Bilge commented 3 years ago

Environment

Sonata packages

show

``` sonata-project/admin-bundle 3.49.1 4.0.0 The missing Symfony Admin Generator sonata-project/block-bundle 3.19.0 4.7.0 Symfony SonataBlockBundle sonata-project/cache 1.1.1 2.2.0 Cache library sonata-project/core-bundle 3.15.1 3.20.0 Symfony SonataCoreBundle sonata-project/datagrid-bundle 2.5.0 3.3.0 Symfony SonataDatagridBundle sonata-project/doctrine-extensions 1.9.1 1.13.1 Doctrine2 behavioral extensions sonata-project/doctrine-orm-admin-bundle 3.13.0 4.0.0 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.7.0 Lightweight Exporter library sonata-project/google-authenticator 1.1.0 2.3.1 Library to integrate Google Authenticator into a PHP project sonata-project/user-bundle 4.1.1 4.11.1 Symfony SonataUserBundle ```

Symfony packages

show

``` symfony/asset v3.4.47 v5.3.4 Symfony Asset Component symfony/assetic-bundle v2.8.2 v2.8.2 Integrates Assetic into Symfony2 Package symfony/assetic-bundle is abandoned, you should avoid using it. Use symfony/webpack-encore-pack instead. symfony/cache v3.4.47 v5.3.7 Symfony Cache component with PSR-6, PSR-16, and tags symfony/class-loader v3.4.47 v3.4.47 Symfony ClassLoader Component symfony/config v3.4.47 v5.3.4 Symfony Config Component symfony/console v3.4.47 v5.3.7 Symfony Console Component symfony/debug v3.4.47 v4.4.27 Symfony Debug Component symfony/dependency-injection v3.4.47 v5.3.7 Symfony DependencyInjection Component symfony/doctrine-bridge v3.4.47 v5.3.7 Symfony Doctrine Bridge symfony/dotenv v3.4.47 v5.3.7 Registers environment variables from a .env file symfony/event-dispatcher v3.4.47 v5.3.7 Symfony EventDispatcher Component symfony/expression-language v3.4.47 v5.3.7 Symfony ExpressionLanguage Component symfony/filesystem v3.4.47 v5.3.4 Symfony Filesystem Component symfony/finder v3.4.47 v5.3.7 Symfony Finder Component symfony/flex v1.15.1 v1.15.3 Composer plugin for Symfony symfony/form v3.4.47 v5.3.7 Symfony Form Component symfony/framework-bundle v3.4.47 v5.3.7 Symfony FrameworkBundle symfony/http-foundation v3.4.47 v5.3.7 Symfony HttpFoundation Component symfony/http-kernel v3.4.49 v5.3.7 Symfony HttpKernel Component symfony/inflector v3.4.47 v5.3.4 Symfony Inflector Component Package symfony/inflector is abandoned, you should avoid using it. Use use `EnglishInflector` from the String component instead instead. symfony/monolog-bridge v3.4.47 v5.3.7 Symfony Monolog Bridge symfony/monolog-bundle v3.6.0 v3.7.0 Symfony MonologBundle symfony/options-resolver v3.4.47 v5.3.7 Symfony OptionsResolver Component symfony/polyfill-apcu v1.23.0 v1.23.0 Symfony polyfill backporting apcu_* functions to lower PHP versions symfony/polyfill-ctype v1.23.0 v1.23.0 Symfony polyfill for ctype functions symfony/polyfill-intl-icu v1.23.0 v1.23.0 Symfony polyfill for intl's ICU-related data and classes symfony/polyfill-mbstring v1.23.1 v1.23.1 Symfony polyfill for the Mbstring extension symfony/polyfill-php54 v1.20.0 v1.20.0 Symfony polyfill backporting some PHP 5.4+ features to lower PHP versions symfony/polyfill-php56 v1.20.0 v1.20.0 Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions symfony/polyfill-php70 v1.20.0 v1.20.0 Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions symfony/process v3.4.47 v5.3.7 Symfony Process Component symfony/property-access v3.4.47 v5.3.7 Symfony PropertyAccess Component symfony/proxy-manager-bridge v3.4.47 v5.3.4 Symfony ProxyManager Bridge symfony/routing v3.4.47 v5.3.7 Symfony Routing Component symfony/security v3.4.49 v4.4.30 Symfony Security Component symfony/security-acl v3.1.2 v3.2.0 Symfony Security Component - ACL (Access Control List) symfony/security-bundle v3.4.48 v5.3.7 Symfony SecurityBundle symfony/serializer v3.4.47 v5.3.4 Symfony Serializer Component symfony/service-contracts v2.4.0 v2.4.0 Generic abstractions related to writing services symfony/swiftmailer-bundle v2.6.7 v3.5.2 Symfony SwiftmailerBundle symfony/templating v3.4.47 v5.3.7 Symfony Templating Component symfony/translation v3.4.47 v5.3.7 Symfony Translation Component symfony/twig-bridge v3.4.47 v5.3.7 Symfony Twig Bridge symfony/twig-bundle v3.4.47 v5.3.4 Symfony TwigBundle symfony/validator v3.4.47 v5.3.7 Symfony Validator Component symfony/var-dumper v3.4.47 v5.3.7 Symfony mechanism for exploring and dumping PHP variables symfony/web-profiler-bundle v3.4.47 v5.3.5 Symfony WebProfilerBundle symfony/yaml v3.4.47 v5.3.6 Symfony Yaml Component ```

PHP version

PHP 7.4.23 (cli) (built: Sep  3 2021 17:58:14) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.23, Copyright (c), by Zend Technologies
    with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans
    with blackfire v1.66.0~linux-x64-non_zts74, https://blackfire.io, by Blackfire

Subject

Upgrading from Symfony 2.8 -> 3.4 necessitates upgrading sonata-project/user-bundle 3.6.0 -> 4.1.1. However, this triggers the following error:

InvalidArgumentException Model class "My\User" does not correspond to manager type "orm". in SonataUserExtension.php line 298

It seems the library demands we extend Sonata\UserBundle\Entity\BaseUser with this hard-coded requirement, but we already extend \FOS\UserBundle\Model\User and we cannot possibly extend both. What should I do?

Full trace

InvalidArgumentException: Model class "My\User" does not correspond to manager type "orm". in /application/vendor/sonata-project/user-bundle/src/DependencyInjection/SonataUserExtension.php:298
Stack trace:
#0 /application/vendor/sonata-project/user-bundle/src/DependencyInjection/SonataUserExtension.php(90): Sonata\UserBundle\DependencyInjection\SonataUserExtension->checkManagerTypeToModelTypeMapping(Array)
#1 /application/vendor/symfony/dependency-injection/Compiler/MergeExtensionConfigurationPass.php(71): Sonata\UserBundle\DependencyInjection\SonataUserExtension->load(Array, Object(Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationContainerBuilder))
#2 /application/vendor/symfony/http-kernel/DependencyInjection/MergeExtensionConfigurationPass.php(39): Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass->process(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
#3 /application/vendor/symfony/dependency-injection/Compiler/Compiler.php(140): Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass->process(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
#4 /application/vendor/symfony/dependency-injection/ContainerBuilder.php(789): Symfony\Component\DependencyInjection\Compiler\Compiler->compile(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
#5 /application/vendor/symfony/http-kernel/Kernel.php(643): Symfony\Component\DependencyInjection\ContainerBuilder->compile()
#6 /application/vendor/symfony/http-kernel/Kernel.php(135): Symfony\Component\HttpKernel\Kernel->initializeContainer()
#7 /application/vendor/symfony/http-kernel/Kernel.php(195): Symfony\Component\HttpKernel\Kernel->boot()
#8 /application/public/index.php(24): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#9 {main}
VincentLanglet commented 3 years ago

It seems the library demands we extend Sonata\UserBundle\Entity\BaseUser with this hard-coded requirement, but we already extend \FOS\UserBundle\Model\User and we cannot possibly extend both. What should I do?

Just extends the BaseUser, since this class already extends \FOS\UserBundle\Model\User.

Bilge commented 3 years ago

An astute observation! Unfortunately, the Sonata base user comes with a whole bunch of extra columns we do not want to support. For example, we already have a created column, we do not want it duplicated by createdAt. I imagine we wouldn't want all of that social stuff or most of the rest of it, either. Why did it suddenly become a hard requirement to have 17 specific personal information fields?

VincentLanglet commented 3 years ago

An astute observation! Unfortunately, the Sonata base user comes with a whole bunch of extra columns we do not want to support. For example, we already have a created column, we do not want it duplicated by createdAt. I imagine we wouldn't want all of that social stuff or most of the rest of it, either. Why did it suddenly become a hard requirement to have 17 specific personal information fields?

Because if the column doesn't exist, we cannot display it https://github.com/sonata-project/SonataUserBundle/blob/4.x/src/Admin/Model/UserAdmin.php#L91

Instead of creating your own created column you have to use the one provided by the bundle. If you want to use you own class, your own admin, etc. You can just creating your own admin and not using this bundle.

Bilge commented 3 years ago

Considering the entire admin backend seems to be propped up by this maze of Sonata packages, I don't think simply not using the bundle is really an option. I can see it being a possibility to migrate created -> createdAt, but it doesn't really answer what we're supposed to do with adding 17+ columns to an already oversized table, none of which we actually need. Why isn't it customizable?

VincentLanglet commented 3 years ago

Considering the entire admin backend seems to be propped up by this maze of Sonata packages, I don't think simply not using the bundle is really an option.

Still, this bundle is optional ; for instance I use sonata packages and don't use this one.

Why isn't it customizable?

I would say it's because

jordisala1991 commented 3 years ago

For now they are required. Probably on next SonataUserBundle they will be removed, but that is not happening soon (maybe in 1-2 months).

As @VincentLanglet said, the bundle is optional. I moved from using it, to implement my own system too, it is not that hard.

Bilge commented 3 years ago

My mistake, then. I assumed this bundle was needed by the Sonata ecosystem, but it is not required by Sonata admin. I am sure it would not be difficult to forego this bundle when starting from scratch, but when it is deeply ingrained into an existing system, simply removing it will be much more difficult. Hence why I am loathe to see we are suddenly forced to accept a ton of new columns as part of a mandatory upgrade. I have a good mind to just fork the old version and declare it compatible with newer versions of Symfony, because it probably is. That way, we wouldn't have to add any new columns.