Skip to content

Missing Metadata Driver in Symfony 3.4.0 BETA 4 #24950

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

Closed
DerKnerd opened this issue Nov 13, 2017 · 8 comments
Closed

Missing Metadata Driver in Symfony 3.4.0 BETA 4 #24950

DerKnerd opened this issue Nov 13, 2017 · 8 comments

Comments

@DerKnerd
Copy link

Q A
Bug report? yes
Feature request? no
BC Break report? yes
RFC? no
Symfony version 3.4.0 BETA4

Hello everyone,

after upgrading my project from Symfony 3.4.0 BETA 2 to 3.4.0 BETA4 I get the following exception in every request and every cli command:

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfon
y-scripts event terminated with an exception


  [RuntimeException]
  An error occurred when executing the ""cache:clear --no-warmup"" command:
  In ORMException.php line 38:


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

Is this a know issue and if yes, is there a work around yet?

You can find the code here: https://github.com/DerKnerd/Jinya-Gallery-CMS

Greetings Knerd

@DerKnerd
Copy link
Author

Ok, after tracing a bit I found the reason why it fails, neverless I have no idea how to fix it. The problem lies in the cached container in the method getDoctrine_Orm_DefaultEntityManagerService there the code that creates the EntityManager is executed before the configuration is filled with data. Does anyone know how to fix that behavior?

@DerKnerd
Copy link
Author

Here is the code of BETA2 cache:

<?php

use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;

// 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.

$a = ${($_ = isset($this->services['annotation_reader']) ? $this->services['annotation_reader'] : $this->load(__DIR__.'/getAnnotationReaderService.php')) && false ?: '_'};

$b = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($a, array(0 => 'D:\\jinya-gallery-cms\\src\\HelperBundle\\Entity', 1 => 'D:\\jinya-gallery-cms\\src\\DataBundle\\Entity'));

$c = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain();
$c->addDriver($b, 'HelperBundle\\Entity');
$c->addDriver($b, 'DataBundle\\Entity');
$c->addDriver(new \Doctrine\ORM\Mapping\Driver\XmlDriver(new \Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator(array('D:\\jinya-gallery-cms\\vendor\\friendsofsymfony\\user-bundle\\Resources\\config\\doctrine-mapping' => 'FOS\\UserBundle\\Model'), '.orm.xml')), 'FOS\\UserBundle\\Model');

$d = new \Doctrine\ORM\Configuration();
$d->setEntityNamespaces(array('HelperBundle' => 'HelperBundle\\Entity', 'DataBundle' => 'DataBundle\\Entity'));
$d->setMetadataCacheImpl(${($_ = isset($this->services['doctrine_cache.providers.doctrine.orm.default_metadata_cache']) ? $this->services['doctrine_cache.providers.doctrine.orm.default_metadata_cache'] : $this->load(__DIR__.'/getDoctrineCache_Providers_Doctrine_Orm_DefaultMetadataCacheService.php')) && false ?: '_'});
$d->setQueryCacheImpl(${($_ = isset($this->services['doctrine_cache.providers.doctrine.orm.default_query_cache']) ? $this->services['doctrine_cache.providers.doctrine.orm.default_query_cache'] : $this->load(__DIR__.'/getDoctrineCache_Providers_Doctrine_Orm_DefaultQueryCacheService.php')) && false ?: '_'});
$d->setResultCacheImpl(${($_ = isset($this->services['doctrine_cache.providers.doctrine.orm.default_result_cache']) ? $this->services['doctrine_cache.providers.doctrine.orm.default_result_cache'] : $this->load(__DIR__.'/getDoctrineCache_Providers_Doctrine_Orm_DefaultResultCacheService.php')) && false ?: '_'});
$d->setMetadataDriverImpl($c);
$d->setProxyDir(($this->targetDirs[0].'/doctrine/orm/Proxies'));
$d->setProxyNamespace('Proxies');
$d->setAutoGenerateProxyClasses(true);
$d->setClassMetadataFactoryName('Doctrine\\ORM\\Mapping\\ClassMetadataFactory');
$d->setDefaultRepositoryClassName('Doctrine\\ORM\\EntityRepository');
$d->setNamingStrategy(new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy());
$d->setQuoteStrategy(new \Doctrine\ORM\Mapping\DefaultQuoteStrategy());
$d->setEntityListenerResolver(${($_ = isset($this->services['doctrine.orm.default_entity_listener_resolver']) ? $this->services['doctrine.orm.default_entity_listener_resolver'] : $this->load(__DIR__.'/getDoctrine_Orm_DefaultEntityListenerResolverService.php')) && false ?: '_'});

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

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

return $instance;

And here is the BETA4 cache

<?php

namespace ContainerXo2t2t9;

use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;

/**
 * This class has been auto-generated
 * by the Symfony Dependency Injection Component.
 *
 * @final since Symfony 3.3
 */
class appDevDebugProjectContainer extends Container
{
/**
     * Gets the public 'doctrine.orm.default_entity_manager' shared service.
     *
     * @return \Doctrine\ORM\EntityManager
     */
    protected function getDoctrine_Orm_DefaultEntityManagerService($lazyLoad = true)
    {
        $a = ${($_ = isset($this->services['doctrine.dbal.default_connection']) ? $this->services['doctrine.dbal.default_connection'] : $this->getDoctrine_Dbal_DefaultConnectionService()) && false ?: '_'};
        $b = ${($_ = isset($this->services['annotation_reader']) ? $this->services['annotation_reader'] : $this->getAnnotationReaderService()) && false ?: '_'};

        if (isset($this->services['doctrine.orm.default_entity_manager'])) {
            return $this->services['doctrine.orm.default_entity_manager'];
        }

        $c = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($b, array(0 => 'D:\\jinya-gallery-cms\\src\\HelperBundle\\Entity', 1 => 'D:\\jinya-gallery-cms\\src\\DataBundle\\Entity'));

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

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

        $this->services['doctrine.orm.default_entity_manager'] = $instance = \Doctrine\ORM\EntityManager::create($a, $e);

        $d->addDriver($c, 'HelperBundle\\Entity');
        $d->addDriver($c, 'DataBundle\\Entity');
        $d->addDriver(new \Doctrine\ORM\Mapping\Driver\XmlDriver(new \Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator(array('D:\\jinya-gallery-cms\\vendor\\friendsofsymfony\\user-bundle\\Resources\\config\\doctrine-mapping' => 'FOS\\UserBundle\\Model'), '.orm.xml')), 'FOS\\UserBundle\\Model');
        $e->setEntityNamespaces(array('HelperBundle' => 'HelperBundle\\Entity', 'DataBundle' => 'DataBundle\\Entity'));
        $e->setMetadataCacheImpl(${($_ = isset($this->services['doctrine_cache.providers.doctrine.orm.default_metadata_cache']) ? $this->services['doctrine_cache.providers.doctrine.orm.default_metadata_cache'] : $this->getDoctrineCache_Providers_Doctrine_Orm_DefaultMetadataCacheService()) && false ?: '_'});
        $e->setQueryCacheImpl(${($_ = isset($this->services['doctrine_cache.providers.doctrine.orm.default_query_cache']) ? $this->services['doctrine_cache.providers.doctrine.orm.default_query_cache'] : $this->getDoctrineCache_Providers_Doctrine_Orm_DefaultQueryCacheService()) && false ?: '_'});
        $e->setResultCacheImpl(${($_ = isset($this->services['doctrine_cache.providers.doctrine.orm.default_result_cache']) ? $this->services['doctrine_cache.providers.doctrine.orm.default_result_cache'] : $this->getDoctrineCache_Providers_Doctrine_Orm_DefaultResultCacheService()) && false ?: '_'});
        $e->setMetadataDriverImpl($d);
        $e->setProxyDir(($this->targetDirs[0].'/doctrine/orm/Proxies'));
        $e->setProxyNamespace('Proxies');
        $e->setAutoGenerateProxyClasses(true);
        $e->setClassMetadataFactoryName('Doctrine\\ORM\\Mapping\\ClassMetadataFactory');
        $e->setDefaultRepositoryClassName('Doctrine\\ORM\\EntityRepository');
        $e->setNamingStrategy(new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy());
        $e->setQuoteStrategy(new \Doctrine\ORM\Mapping\DefaultQuoteStrategy());
        $e->setEntityListenerResolver(${($_ = isset($this->services['doctrine.orm.default_entity_listener_resolver']) ? $this->services['doctrine.orm.default_entity_listener_resolver'] : $this->services['doctrine.orm.default_entity_listener_resolver'] = new \Doctrine\Bundle\DoctrineBundle\Mapping\ContainerAwareEntityListenerResolver($this)) && false ?: '_'});

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

        return $instance;
    }
}

The BETA2 cache lies in its own file, whilst the BETA4 cache is in the Container. There the configuration is filled after the EntityManager got created.

@backbone87
Copy link
Contributor

can confirm, problem was introduced with BETA3

@backbone87
Copy link
Contributor

backbone87 commented Nov 14, 2017

the problem is that: $this->services['doctrine.orm.default_entity_manager'] = $instance = \Doctrine\ORM\EntityManager::create($a, $e); moved before the actual configuration of the services $a and $e

probably introduced by db12a98 or beb4df7

edit: the following ORM config is used

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy:             doctrine.orm.naming_strategy.underscore
        auto_mapping:                true
        mappings:
            App:
                type:      annotation
                is_bundle: false
                dir:       "%kernel.project_dir%/src/Entity"
                prefix:    App\Entity

@sroze
Copy link
Contributor

sroze commented Nov 15, 2017

@DerKnerd @backbone87 could you create a very simple Symfony application with this exception and share the link to it here? I can't reproduce.

@nicolas-grekas
Copy link
Member

Should be fixed by #25055

@DerKnerd
Copy link
Author

@sroze Do you still need the simple app? I could create it to Wednesday.

@nicolas-grekas
Copy link
Member

@DerKnerd I guess not, I reproduced and fixed the issue :)

nicolas-grekas added a commit that referenced this issue Nov 20, 2017
…grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Analyze setter-circular deps more precisely

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

This PR reverts the effect of #24828 and #24822 on fixtures, except for the new behavior these PRs introduced, which was mostly fine, but missed a few cases.
This PR now uses the reference graph to precisely decide which services need circular dependency care, and does not touch the other ones.

Commits
-------

9cc4a21 [DI] Analyze setter-circular deps more precisely
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

6 participants