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

UnitOfWork pre update invoke causes some times fatal errors #5605

Closed
ghost opened this issue Jan 11, 2016 · 9 comments
Closed

UnitOfWork pre update invoke causes some times fatal errors #5605

ghost opened this issue Jan 11, 2016 · 9 comments
Assignees
Labels
Milestone

Comments

@ghost
Copy link

ghost commented Jan 11, 2016

I've the same problem like described in #3468. Somehow the change set for the entity is gone while calling the commit function. I guess it will work if one changes the following line of code.

$this->listenersInvoker->invoke($class, Events::preUpdate, $entity, new PreUpdateEventArgs($entity, $this->em, $this->entityChangeSets[$oid]), $preUpdateInvoke);

To use the method "getEntityChangeSet" to force to get an array. Because it does the same like before in a cleaner manner and one will always get an array back.

$this->listenersInvoker->invoke($class, Events::preUpdate, $entity, new PreUpdateEventArgs($entity, $this->em, $this->getEntityChangeSet($entity)), $preUpdateInvoke);

(https://github.com/doctrine/doctrine2/blob/16972935917307c49c6a423edcc1fbb711e0d483/lib/Doctrine/ORM/UnitOfWork.php#L1052)

This is my first ticket creation for the doctrine2 project, I hope it will help to improve the project.

@Ocramius
Copy link
Member

@sr-amueller the initial issue ( #3468 ) was closed due to lack of tests: can you reproduce the issue in isolation?

@ghost
Copy link
Author

ghost commented Jan 11, 2016

@Ocramius Not right now, but I will try to reproduce it the issue in isolation in the next few days.

@Ocramius
Copy link
Member

@sr-amueller thanks :-)

@Bencsi
Copy link

Bencsi commented Jan 29, 2016

In my case the problem was, $em = $this->getDoctrine()->getManager(); inside a try block, I moved this line above the try block, problem solved. :)

@dontub
Copy link

dontub commented May 11, 2017

I think this might happen when flush() is called a second time during a running flush. The foreach in executeUpdates() iterates over entityUpdates in the state when the loop was started so the current entityUpdates and entityChangeSets might not contain the entity, anymore. In that case the following code at the beginning of the loop would be a possible solution:

if (!isset($this->entityUpdates[$oid])) {
    continue;
}

As commented in 86cde3a that fix leads to another error.

Aside: I'm wondering why the preUpdate event occurs during the flush whereas prePersist und preRemove occur immediately when persist() or remove() is called.

@apoorva-shah
Copy link

apoorva-shah commented May 18, 2017

I still got this error

Argument 3 passed to Doctrine\ORM\Event\PreUpdateEventArgs::__construct() must be of the type array, null given, called in UnitOfWork.php on line 1060

In controller

removeExpireProducts();
$em->flush();

Inside my service:

function removeExpireProducts()
{
    foreach ($products as $product) {
      $em->remove($product);
    }
}

Please suggest.

@Ocramius
Copy link
Member

I think this might happen when flush() is called a second time during a running flush.

Flushing inside a flush operation is not supported, so that scenario is pretty much invalid.

@apoorva-shah
Copy link

Hello @Ocramius thanks, but i did not understand
Flushing inside a flush operation is not supported, so that scenario is pretty much invalid.
Can you explain more? how to avoid this error?

@lcobucci
Copy link
Member

@apoorva-shah EntityManager#flush() will commit the Unit of Work (UoW) which will then compute the changeset that needs to be applied to the persistence layer. Committing UoW changes in the middle of a commit causes inconsistencies and therefore is invalid.

You can read http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html for more information.

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

No branches or pull requests

6 participants