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

Resource repositories using EntityRepository use EntityManager object directly instead of proxy #980

Open
Michal-Szczepaniak opened this issue Feb 14, 2025 · 1 comment · May be fixed by #981

Comments

@Michal-Szczepaniak
Copy link

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.

@loic425
Copy link
Member

loic425 commented Feb 14, 2025

Thx a lot for reporting this issue.
We'll fix that soon.

@loic425 loic425 linked a pull request Feb 14, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants