Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error "It's a requirement to specify a Metadata Driver..." after Upgrade to 4.1.4 #28304

Closed
ThomasTr opened this issue Aug 29, 2018 · 63 comments
Closed

Comments

@ThomasTr
Copy link
Contributor

ThomasTr commented Aug 29, 2018

Symfony version(s) affected: 4.1.4

Description
After Upgrade from 4.1.3 to 4.1.4 i get the following error:

It's a requirement to specify a Metadata Driver and pass it to Doctrine\ORM\Configuration::setMetadataDriverImpl().

EDIT: if you still have this issue, running composer require symfony/proxy-manager-bridge should fix it.

Trace: ``` in ORMException.php line 38 -- at ORMException::missingMappingDriverImpl()in EntityManager.php line 845 at EntityManager::create(object(Connection), object(Configuration))in srcDevDebugProjectContainer.php line 698 at srcDevDebugProjectContainer->getDoctrine_Orm_DefaultEntityManagerService()in Container.php line 242 at Container->make('doctrine.orm.default_entity_manager', 1)in Container.php line 222 at Container->get('doctrine.orm.default_entity_manager')in ManagerRegistry.php line 35 at ManagerRegistry->getService('doctrine.orm.default_entity_manager')in AbstractManagerRegistry.php line 200 at AbstractManagerRegistry->getManagers()in ProxyCacheWarmer.php line 49 at ProxyCacheWarmer->warmUp('E:\\www\\ltgsc\\var\\cache\\dev')in CacheWarmerAggregate.php line 57 at CacheWarmerAggregate->warmUp('E:\\www\\ltgsc\\var\\cache\\dev')in Kernel.php line 562 at Kernel->initializeContainer()in Kernel.php line 123 at Kernel->boot()in Kernel.php line 183 at Kernel->handle(object(Request))in index.php line 34 ```` To be updated: ``` composer outdated --direct friendsofphp/php-cs-fixer v2.12.2 v2.13.0 A tool to automatically fix PHP code style symfony/browser-kit v4.1.3 v4.1.4 Symfony BrowserKit Component symfony/console v4.1.3 v4.1.4 Symfony Console Component symfony/css-selector v4.1.3 v4.1.4 Symfony CssSelector Component symfony/debug-bundle v4.1.3 v4.1.4 Symfony DebugBundle symfony/dotenv v4.1.3 v4.1.4 Registers environment variables from a .env file symfony/expression-language v4.1.3 v4.1.4 Symfony ExpressionLanguage Component symfony/flex v1.0.89 v1.1.0 Composer plugin for Symfony symfony/form v4.1.3 v4.1.4 Symfony Form Component symfony/framework-bundle v4.1.3 v4.1.4 Symfony FrameworkBundle symfony/lock v4.1.3 v4.1.4 Symfony Lock Component symfony/maker-bundle v1.5.0 v1.6.0 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code. symfony/phpunit-bridge v4.1.3 v4.1.4 Symfony PHPUnit Bridge symfony/polyfill-apcu v1.8.0 v1.9.0 Symfony polyfill backporting apcu_* functions to lower PHP versions symfony/security-bundle v4.1.3 v4.1.4 Symfony SecurityBundle symfony/templating v4.1.3 v4.1.4 Symfony Templating Component symfony/translation v4.1.3 v4.1.4 Symfony Translation Component symfony/validator v4.1.3 v4.1.4 Symfony Validator Component symfony/var-dumper v4.1.3 v4.1.4 Symfony mechanism for exploring and dumping PHP variables symfony/web-server-bundle v4.1.3 v4.1.4 Symfony WebServerBundle symfony/yaml v4.1.3 v4.1.4 Symfony Yaml Component ``` Update: ``` composer update && composer dump-autoload --optimize Loading composer repositories with package information Updating dependencies (including require-dev)

Prefetching 41 packages

  • Downloading (100%)

Package operations: 1 install, 58 updates, 0 removals

  • Updating symfony/flex (v1.0.89 => v1.1.0): Loading from cache
  • Updating symfony/dotenv (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/cache (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/polyfill-apcu (v1.8.0 => v1.9.0): Loading from cache
  • Updating symfony/expression-language (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/polyfill-ctype (v1.8.0 => v1.9.0): Loading from cache
  • Updating symfony/inflector (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/property-access (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/polyfill-php70 (v1.8.0 => v1.9.0): Loading from cache
  • Updating symfony/polyfill-mbstring (v1.8.0 => v1.9.0): Loading from cache
  • Updating symfony/options-resolver (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/intl (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/polyfill-intl-icu (v1.8.0 => v1.9.0): Loading from cache
  • Updating symfony/event-dispatcher (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/form (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/lock (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/http-foundation (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/debug (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/http-kernel (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/routing (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/finder (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/filesystem (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/dependency-injection (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/config (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/framework-bundle (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/console (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/maker-bundle (v1.5.0 => v1.6.0): Loading from cache
  • Updating symfony/security (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/security-bundle (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/templating (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/translation (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/validator (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/yaml (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/stopwatch (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/process (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/polyfill-php72 (v1.8.0 => v1.9.0): Loading from cache
  • Updating composer/xdebug-handler (1.1.0 => 1.2.1): Loading from cache
  • Updating friendsofphp/php-cs-fixer (v2.12.2 => v2.13.0): Loading from cache
  • Updating symfony/dom-crawler (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/browser-kit (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/css-selector (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/var-dumper (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/twig-bridge (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/debug-bundle (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/phpunit-bridge (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/web-server-bundle (v4.1.3 => v4.1.4): Loading from cache
  • Updating doctrine/cache (v1.7.1 => v1.8.0): Loading from cache
  • Updating doctrine/persistence (v1.0.0 => v1.0.1): Loading from cache
  • Updating symfony/doctrine-bridge (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/twig-bundle (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/web-profiler-bundle (v4.1.3 => v4.1.4): Loading from cache
  • Updating symfony/serializer (v4.1.3 => v4.1.4): Loading from cache
  • Installing markbaker/complex (1.4.6): Loading from cache
  • Updating phpoffice/phpspreadsheet (1.3.1 => 1.4.0): Loading from cache
  • Updating egulias/email-validator (2.1.4 => 2.1.5): Loading from cache
  • Updating knplabs/knp-components (1.3.8 => v1.3.9): Loading from cache
  • Updating symfony/monolog-bridge (v4.1.3 => v4.1.4): Loading from cache
  • Updating zendframework/zend-code (3.3.0 => 3.3.1): Loading from cache
  • Updating ocramius/proxy-manager (2.2.0 => 2.2.1): Loading from cache

My Doctrine Config:

parameters:
# Adds a fallback DATABASE_URL if the env var is not set.
# This allows you to run cache:warmup even if your
# environment variables are not available yet.
# You should not need to change this value.
env(DATABASE_URL): ''

doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8

    # With Symfony 3.3, remove the `resolve:` prefix
    url: '%env(DATABASE_URL)%'
orm:
    auto_generate_proxy_classes: '%kernel.debug%'
    naming_strategy: doctrine.orm.naming_strategy.underscore
    auto_mapping: true
    mappings:
        XXXX:
            is_bundle: false
            type: annotation
            dir: '%kernel.project_dir%/src/Entity'
            prefix: 'XXXX\Entity'
            alias: XXXX

</details>
@koddistortion
Copy link

I can confirm this issue after upgrading from Symfony 3.4.14 to 3.4.15.

@poethrenoff
Copy link

Also had same trouble while upgrading from 4.1.3 to 4.1.4.

@xabbuh
Copy link
Member

xabbuh commented Aug 30, 2018

Can one of you create a small example application that allows to reproduce?

@ThomasTr
Copy link
Contributor Author

It happens on a bigger closed source project, i am working on. I'm currently trying to figure out the cause by updating each package individually. I hope to be able to give more details soon.

@ThomasTr
Copy link
Contributor Author

Done the updates step by step on this project and after doing this particular update the error occures:

composer update symfony/dependency-injection
Loading composer repositories with package information                                       Updating dependencies (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Updating symfony/dependency-injection (v4.1.3 => v4.1.4): Loading from cache

Seems one of these commits is causing this issue:
symfony/dependency-injection@v4.1.3...v4.1.4

I investigate further.

@nielsvandermolen
Copy link

+1 Confirming that downgrading the dependency injection package to 4.1.3 resolved the issue.

@romeodeb
Copy link

I had exactly the same error while upgrading Symfony 3.4.13 to 3.4.15. When disabling doctrine tag "doctrine.orm.entity_listener" on the services that used it, there's no more errors (not a solution but a diagnose). In my case cache:clear failed and the entire project is broken so i'm staying in 3.4.13.

@nicolas-grekas
Copy link
Member

Can anyone provide a reproducer, and maybe also find the commit which introduced this?

@nicolas-grekas
Copy link
Member

Does composer require symfony/proxy-manager-bridge fix the issue?

@ThomasTr
Copy link
Contributor Author

ThomasTr commented Sep 4, 2018

For me it's also the "doctrine.orm.entity_listener" from 2 doctrine event listener i use. After commenting them out it works (also not a solution but a diagnose).

And yes, with suggested "symfony/proxy-manager-bridge" it works (with doctrine event listener).

Will try to build a small reproducer.

@nicolas-grekas
Copy link
Member

Can you please report if applying #28366 fixes your issue?

@phansys
Copy link
Contributor

phansys commented Sep 4, 2018

#28366 doesn't fix the issue, If I can, I'll try to provide some context.

// var/cache/local/ContainerH1kverd/appLocalDebugProjectContainer.php

    /**
     * Gets the public 'doctrine.orm.my_entity_manager' shared service.
     *
     * @return \Doctrine\ORM\EntityManager
     */
    protected function getDoctrine_Orm_MyEntityManagerService($lazyLoad = true)
    {
        $a = new \Doctrine\ORM\Configuration();

        $this->services['doctrine.orm.my_entity_manager'] = $instance = \Doctrine\ORM\EntityManager::create(${($_ = isset($this->services['doctrine.dbal.default_connection']) ? $this->services['doctrine.dbal.default_connection'] : $this->getDoctrine_Dbal_DefaultConnectionService()) && false ?: '_'}, $a);

        $b = new \Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver(array(($this->targetDirs[3].'/vendor/sonata-project/media-bundle/src/Resources/config/doctrine') => 'Sonata\\MediaBundle\\Entity', ($this->targetDirs[3].'/vendor/sonata-project/user-bundle/src/Resources/config/doctrine') => 'Sonata\\UserBundle\\Entity'));
        $b->setGlobalBasename('mapping');

        $c = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver(${($_ = isset($this->services['annotation_reader']) ? $this->services['annotation_reader'] : $this->getAnnotationReaderService()) && false ?: '_'}, array(0 => ($this->targetDirs[3].'/vendor/gesdinet/jwt-refresh-token-bundle/Entity'), 1 => ($this->targetDirs[3].'/vendor/hackzilla/ticket-bundle/Entity')));

        $d = new \Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver(array(($this->targetDirs[3].'/src/MyBundle/Resources/config/doctrine') => 'MyBundle\\Entity'));
        $d->setGlobalBasename('mapping');

        $e = new \Doctrine\ORM\Mapping\Driver\YamlDriver(new \Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator(array(($this->targetDirs[3].'/vendor/gesdinet/jwt-refresh-token-bundle/Resources/config/doctrine-orm') => 'Gesdinet\\JWTRefreshTokenBundle\\Entity', ($this->targetDirs[3].'/vendor/gesdinet/jwt-refresh-token-bundle/Resources/config/doctrine-entity') => 'Gesdinet\\JWTRefreshTokenBundle\\Entity'), '.orm.yml'));

        $f = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain();

        $f->addDriver($b, 'Sonata\\MediaBundle\\Entity');
        $f->addDriver($b, 'Sonata\\UserBundle\\Entity');
        $f->addDriver($c, 'Gesdinet\\JWTRefreshTokenBundle\\Entity');
        $f->addDriver($c, 'Hackzilla\\Bundle\\TicketBundle\\Entity');
        $f->addDriver($d, 'MyBundle\\Entity');
        $f->addDriver(new \Doctrine\ORM\Mapping\Driver\XmlDriver(new \Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator(array(($this->targetDirs[3].'/vendor/friendsofsymfony/user-bundle/Resources/config/doctrine-mapping') => 'FOS\\UserBundle\\Model'), '.orm.xml')), 'FOS\\UserBundle\\Model');
        $f->addDriver($e, 'Gesdinet\\JWTRefreshTokenBundle\\Entity');
        $f->addDriver($e, 'Gesdinet\\JWTRefreshTokenBundle\\Entity');
        $a->setEntityNamespaces(array('SonataMediaBundle' => 'Sonata\\MediaBundle\\Entity', 'SonataUserBundle' => 'Sonata\\UserBundle\\Entity', 'GesdinetJWTRefreshTokenBundle' => 'Gesdinet\\JWTRefreshTokenBundle\\Entity', 'HackzillaTicketBundle' => 'Hackzilla\\Bundle\\TicketBundle\\Entity', 'MyBundle' => 'MyBundle\\Entity'));
        $a->setMetadataCacheImpl(${($_ = isset($this->services['doctrine_cache.providers.doctrine.orm.my_metadata_cache']) ? $this->services['doctrine_cache.providers.doctrine.orm.my_metadata_cache'] : $this->getDoctrineCache_Providers_Doctrine_Orm_MyMetadataCacheService()) && false ?: '_'});
        $a->setQueryCacheImpl(${($_ = isset($this->services['doctrine_cache.providers.doctrine.orm.my_query_cache']) ? $this->services['doctrine_cache.providers.doctrine.orm.my_query_cache'] : $this->getDoctrineCache_Providers_Doctrine_Orm_MyQueryCacheService()) && false ?: '_'});
        $a->setResultCacheImpl(${($_ = isset($this->services['doctrine_cache.providers.doctrine.orm.my_result_cache']) ? $this->services['doctrine_cache.providers.doctrine.orm.my_result_cache'] : $this->getDoctrineCache_Providers_Doctrine_Orm_MyResultCacheService()) && false ?: '_'});
        $a->setMetadataDriverImpl($f);
        $a->setProxyDir(($this->targetDirs[0].'/doctrine/orm/Proxies'));
        $a->setProxyNamespace('Proxies');
        $a->setAutoGenerateProxyClasses(false);
        $a->setClassMetadataFactoryName('Doctrine\\ORM\\Mapping\\ClassMetadataFactory');
        $a->setDefaultRepositoryClassName('Doctrine\\ORM\\EntityRepository');
        $a->setNamingStrategy(new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy());
        $a->setQuoteStrategy(new \Doctrine\ORM\Mapping\DefaultQuoteStrategy());
        $a->setEntityListenerResolver(${($_ = isset($this->services['doctrine.orm.my_entity_listener_resolver']) ? $this->services['doctrine.orm.my_entity_listener_resolver'] : $this->getDoctrine_Orm_MyEntityListenerResolverService()) && false ?: '_'});
        $a->setRepositoryFactory(new \Doctrine\Bundle\DoctrineBundle\Repository\ContainerRepositoryFactory(new \Symfony\Component\DependencyInjection\ServiceLocator(array())));
        $a->addCustomStringFunction('sha2', 'DoctrineExtensions\\Query\\Mysql\\Sha2');
        $a->addCustomStringFunction('group_concat', 'DoctrineExtensions\\Query\\Mysql\\GroupConcat');
        $a->addCustomStringFunction('substring_index', 'DoctrineExtensions\\Query\\Mysql\\SubstringIndex');
        $a->addCustomDatetimeFunction('timestampdiff', 'DoctrineExtensions\\Query\\Mysql\\TimestampDiff');
        $a->addFilter('softdeleteable', 'Gedmo\\SoftDeleteable\\Filter\\SoftDeleteableFilter');
        $a->addFilter('my_filter', 'MyBundle\\Doctrine\\MyFilter');

        ${($_ = isset($this->services['doctrine.orm.my_manager_configurator']) ? $this->services['doctrine.orm.my_manager_configurator'] : $this->services['doctrine.orm.my_manager_configurator'] = new \Doctrine\Bundle\DoctrineBundle\ManagerConfigurator(array(0 => 'softdeleteable', 1 => 'my_filter'), array())) && false ?: '_'}->configure($instance);

        return $instance;
    }

@phansys
Copy link
Contributor

phansys commented Sep 4, 2018

I left some context from appLocalDebugProjectContainer at #28304 (comment).

nicolas-grekas added a commit that referenced this issue Sep 5, 2018
This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Fix dumping some complex service graphs

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #28296 (and its duplicates #28355 & #28362 ~+ possibly #28304~)
| License       | MIT
| Doc PR        | -

Commits
-------

769fd4b [DI] Fix dumping some complex service graphs
@nicolas-grekas
Copy link
Member

nicolas-grekas commented Sep 5, 2018

I think I now understand where the issue comes from. It's unrelated to #28366 indeed. The issue is that in some situations, in order to resolve some circular loops, we call setters on inline services after injecting them into their consumer. This doesn't play well with runtime checks like the one done in EntityManager.

The fix, for now at least, is to composer require symfony/proxy-manager-bridge, because the situation I'm referring to happens only when this package is not installed (installing it enables some superpower of the DI container, namely to instantiate some services lazily - you definitely want it on real world apps.)

I fear a real fix might be out of reach for 3.4/4.1 but I'll have a better look.

@ThomasTr
Copy link
Contributor Author

ThomasTr commented Sep 5, 2018

Ok, this solution works for me. Thank you for taking care of this problem.

@phansys
Copy link
Contributor

phansys commented Sep 5, 2018

Confirmed, thank you!

@nicolas-grekas nicolas-grekas self-assigned this Sep 5, 2018
@phansys
Copy link
Contributor

phansys commented Sep 5, 2018

I can confirm adding dependency for symfony/proxy-manager-bridge also fixes this #26778 (comment).

@ThomasTr ThomasTr closed this as completed Sep 5, 2018
@nicolas-grekas
Copy link
Member

I'm reopening to keep track of the issue. I've a local reproducer where the reordering leads to a fatal error.

@nicolas-grekas nicolas-grekas reopened this Sep 5, 2018
@ThomasTr
Copy link
Contributor Author

ThomasTr commented Sep 6, 2018

Is ok, since for me, it seems there is another issue (these comes only, when the listener is used, the issue above was on every page even when the listener was not used): After upgrading symfony/dependency-injection to 4.1.4 and installing symfony/proxy-manager-bridge i got the following error with my listener:

Too few arguments to function XXX\EventListener\EntityListener::__construct(), 0 passed in \vendor\doctrine\doctrine-bundle\Mapping\ContainerAwareEntityListenerResolver.php on line 76 and exactly 3 expected

  at src\EventListener\EntityListener.php:26
  at XXX\EventListener\EntityListener->__construct()
     (vendor\doctrine\doctrine-bundle\Mapping\ContainerAwareEntityListenerResolver.php:76)
  at Doctrine\Bundle\DoctrineBundle\Mapping\ContainerAwareEntityListenerResolver->resolve('LTGSC\\EventListener\\RmaEntityListener')
     (vendor\doctrine\orm\lib\Doctrine\ORM\Event\ListenersInvoker.php:110)
  at Doctrine\ORM\Event\ListenersInvoker->invoke(object(ClassMetadata), 'preUpdate', object(Rma), object(PreUpdateEventArgs), 7)
     (vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php:1151)
  at Doctrine\ORM\UnitOfWork->executeUpdates(object(ClassMetadata))
     (vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php:392)
  at Doctrine\ORM\UnitOfWork->commit(null)
     (vendor\doctrine\orm\lib\Doctrine\ORM\EntityManager.php:359)
  at Doctrine\ORM\EntityManager->flush(null)
     (var\cache\dev\Container2Y6TS4n\EntityManager_9a5be93.php:125)
  at EntityManager_9a5be93->flush()
     (src\Controller\ExportController.php:40)
  at XXX\Controller\ExportController->exportServiceReportAction(object(RmaProduct), object(Request), object(EntityManager_9a5be93), object(Serializer))
     (vendor\symfony\http-kernel\HttpKernel.php:149)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor\symfony\http-kernel\HttpKernel.php:66)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor\symfony\http-kernel\Kernel.php:188)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (public\index.php:34)

The constructor injection doesn't work anymore.

This is my constructor for the entity listener:

use XXX\DependencyInjection\Mail;
use XXX\Entity\XXX;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Symfony\Component\Translation\TranslatorInterface;

  public function __construct(Mail $mail, TranslatorInterface $translator, $config)
    {
        $this->mail = $mail;
        $this->translator = $translator;
        $this->config = $config;
    }

And this is the service configuration:

    XXX\EventListener\EntityListener:
        lazy: true
        arguments:
            $config: '%mail%'
        tags:
            - { name: "doctrine.orm.entity_listener", entity: XXX\Entity\XXX, event: preUpdate }

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Sep 6, 2018

Could you please try #28385 (@hal869 also?)
proxy-manager shouldn't be needed anymore to work around the issue.

@nicolas-grekas
Copy link
Member

OK, now I reproduce the "Too few arguments" error, investigating.

@ThomasTr
Copy link
Contributor Author

Thank you 👍

@nicolas-grekas
Copy link
Member

So, looking at the code, adding lazy: true is not supported by doctrine-bundle. The reason is that its ContainerAwareEntityListenerResolver uses get_class(), which doesn't work on lazy proxies.
Instead, "lazy" should be set on the tag (not on the definition itself.)
Might be worth an issue on doctrine-bundle.

@nicolas-grekas
Copy link
Member

See doctrine/DoctrineBundle#849

@nicolas-grekas
Copy link
Member

Which means this issue is solved. Thank you all for the help!

nicolas-grekas added a commit that referenced this issue Sep 19, 2018
This PR was merged into the 3.4 branch.

Discussion
----------

[DI] fix dumping lazy services

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #28304
| License       | MIT
| Doc PR        | -

Commits
-------

7cf1505 [DI] fix dumping lazy services
@ThomasTr
Copy link
Contributor Author

Looks like I'm missing a DB now. Anyway, can you check all these behaviors disappear when applying the patch on PhpDumper.php like in #28507?

Seems to work for my issue: don't get the error "It's a requirement to specify a Metadata Driver..." without the proxy-manager-bridge anymore

@tvequaud
Copy link

Had the same issue on SF 4.1.4... Works for me too after upgrade to SF4.1.6.

@ro0NL
Copy link
Contributor

ro0NL commented Oct 27, 2018

Any chance this happens again in 4.2 =/

It's a requirement to specify a Metadata Driver and pass it to Doctrine\ORM\Configuration::setMetadataDriverImpl().

getDoctrine_Orm_DefaultEntityManagerService.php

<?php

use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;

// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
// Returns the public 'doctrine.orm.default_entity_manager' shared service.

include_once $this->targetDirs[3].'/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/ObjectManager.php';
// ...

$a = new \Doctrine\ORM\Configuration();

$this->services['doctrine.orm.default_entity_manager'] = $instance = \Doctrine\ORM\EntityManager::create(($this->services['doctrine.dbal.default_connection'] ?? $this->load('getDoctrine_Dbal_DefaultConnectionService.php')), $a);

$b = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain();
$c = new \Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver(array(($this->targetDirs[0].'/msgphp/doctrine-mapping') => 'MsgPhp'));
$c->setGlobalBasename('mapping');

$b->addDriver(new \Doctrine\ORM\Mapping\Driver\AnnotationDriver(($this->privates['annotations.cached_reader'] ?? $this->load('getAnnotations_CachedReaderService.php')), array(0 => ($this->targetDirs[3].'/src/Entity'))), 'App\\Entity');

//.. 
$a->setMetadataDriverImpl($b);
//...

(new \Doctrine\Bundle\DoctrineBundle\ManagerConfigurator(array(), array()))->configure($instance);

return $instance;

@gmponos
Copy link
Contributor

gmponos commented Nov 7, 2018

I have the same issue when I switch my env from dev to prod

doctrine/doctrine-bundle 1.9.1
symfony version: v4.1.7

@nicolas-grekas
Copy link
Member

Can you please confirm this is fixed in 4.1@dev version?

@gmponos
Copy link
Contributor

gmponos commented Nov 8, 2018

@nicolas-grekas yes this fixes the problem.. What is the change that was introduced from 4.1.7 to dev that fixes this?

@nicolas-grekas
Copy link
Member

That one: #29103

@kissifrot
Copy link

Well I just ran into this problem when doing the sf 4.1.7 -> 4.1.8.
composer require symfony/proxy-manager-bridge fixed it, but it's another direct unneeded dependency ;)

@nicolas-grekas
Copy link
Member

This issue is driving me crazy :)
I absolutely need a reproducer please.

@tvequaud
Copy link

tvequaud commented Nov 27, 2018 via email

@nicolas-grekas
Copy link
Member

@kissifrot fixed!

@kissifrot
Copy link

@nicolas-grekas Yay! What was the problem?

@nicolas-grekas
Copy link
Member

Doctrine bundle defining a Configuration object as a service and forcing a specific way to dump it. Complex issue :)

@icedevelopment
Copy link

I'm getting the same error when updating from 3.4.18 to 3.4.19.

@wiseguy1394
Copy link
Contributor

I'm getting the same error with symfony 5.0.8.
This error is mainly thrown if i use console commands. In the shutdown function of the doctrine bundle the entity Manager is injected as proxy.

If it than calls the clear method the error is thrown when the proxy is trying to instantiate the entityManager.

https://github.com/doctrine/DoctrineBundle/blob/f5a5a3dd1351818080b609b544608b472b07029f/DoctrineBundle.php#L107-115

The $this->container->get($id) returns a proxy.
I'm using the proxy-manager-bridge.

Actual I'm decorating the EntityManager with my own factorymethod to prevent it from beeing lazy.

Is there any config option I'm missing or is this unwanted behaviour?
Can't reproduce it with a fresh system.

@stollr
Copy link
Contributor

stollr commented Jan 17, 2023

I am getting this error after the update from Symfony 5.4.16 to 5.4.17 in the prod environment as long as the proxy-manager-bridge isn't installed.

@xabbuh
Copy link
Member

xabbuh commented Jan 20, 2023

Commenting on a closed issue will not help add your comments are likely to get lost. Please open a new issue and provide an example application that allows to reproduce it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests