You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
I found out that it is possible to get different instances of the same service (eg: entity manager) during a single execution.
How to reproduce
class MyDoctrineSubscriber implements \Doctrine\Common\EventSubscriber
{
protected $myService;
public function __construct(MyService $myService)
{
$this->myService = $myService;
}
public function preFlush(PreFlushEventArgs $args)
{
// an instance of the entity manager
$entityManager = $args->getEntityManager();
$this->myService->doSomething();
}
public function getSubscribedEvents()
{
return [
Events::preFlush,
];
}
}
class MyService
{
protected $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
// another instance of the same entity manager (!?)
$this->entityManager = $entityManager;
}
public function doSomething()
{
$myEntity = new MyEntity();
// entity is not persisted as persist and flush are called on different instances
$this->entityManager->persist($myEntity);
}
}
Is that an expected behavior?
The text was updated successfully, but these errors were encountered:
your service probably gets the proxy object (DoctrineBundle defines the EntityManager as a lazy service, to be able to replace the actual instance if we need to reset the entity manager, as that feature is not available natively in Doctrine ORM) while the event object contains the actual instance directly (as it gets instantiated by the actual instance, passing $this).
That was always the case, even without the bug.
Symfony version(s) affected: 3.4.22
Description
I found out that it is possible to get different instances of the same service (eg: entity manager) during a single execution.
How to reproduce
Is that an expected behavior?
The text was updated successfully, but these errors were encountered: