-
-
Couldn't load subscription status.
- Fork 163
Description
Sylius version affected: 1.11-1.14 I didn't check 2.0 but on 1.13 branch the problem still exists.
Description
If Resource doesn't have custom repository class it uses EntityRepository and in src/Bundle/DependencyInjection/Driver/Doctrine/DoctrineORMDriver.php:63 the repository is created by executing getRepository on EntityManager class and inside that method, the repository is given $this refering to EntityManager, so instead of holding the proxy it holds object directly, which then creates issue if you wanna use ManagerRegistry to reset the EntityManager.
But if you look into else of the if in the mentioned file, if resource is using custom repository class, it's using $definition->setArguments([$managerReference, $this->getClassMetadataDefinition($metadata)]);, which will give it the EntityManager proxy which works with ManagerRegistry.
Steps to reproduce
Any repository that uses EntityRepository has EntityManager object instead of Proxy.
Possible Solution
Simplest solution would be not to use the factory but create the repository in the same way as it is done in the else statement aka
replace
$definition->setFactory([$managerReference, 'getRepository']);
setArguments([$entityClass]);
with
$definition->setArguments([$managerReference, $this->getClassMetadataDefinition($metadata)]);
and it works just fine.