Orm: UnitOfWork::executeUpdates iterates through an empty entityUpdates array

Created on 13 Dec 2017  Â·  9Comments  Â·  Source: doctrine/orm

Linux Gentoo 4.10.8
PHP 7.1.11 (cli) (built: Nov 3 2017 01:56:43) ( ZTS )
Doctrine VERSION = '2.5.13';
Symfony 3.4

Type error: Argument 3 passed to Doctrine\ORM\Event\PreUpdateEventArgs::__construct() must be of the type array, null given, called in /vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 1064

I tracked down the problem (see UnitOfWork::executeUpdates function) and I've found that at the line 1053 if I would test the condition count($this->entityUpdates) === 0 it would return true because the entityUpdates is really empty.

Despite that the foreach loop at line 1053 seems to want to iterate (which I assume is a very strange condition/bug, I never encountered that from PHP 5 to 7):

Due to this condition the $this->entityChangeSets[$oid] at line 1060 is evaluated to NULL which will throw the "Argument 3 passed..." exception mentioned earlier.

I fixed that problem by adding the following code just inside the loop, at line 1054:

if(0===count($this->entityUpdates)){ continue; }

Bug Missing Tests

All 9 comments

Came here to report this exact issue. Thanks for writing it up!

Been hit by this issue a couple times, got around it by reworking our flush orders. This should ideally not fire the event if no changes have been made to the entity.

Requires a test case

On 14 Dec 2017 17:16, "javabudd" notifications@github.com wrote:

Been hit by this issue a couple times, got around it by reworking our
flush orders. This should ideally not fire the listener if no changes have
been made to the entity.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/doctrine/doctrine2/issues/6884#issuecomment-351758220,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJakMSBgGjI7VsRK4sr-ca8TZttdyHEks5tAUnZgaJpZM4RASRW
.

It looks like the master branch has had this issue resolved for some time but is not in the latest tagged version 2.5.13

master - https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/UnitOfWork.php#L1097
2.5.13 - https://github.com/doctrine/doctrine2/blob/v2.5.13/lib/Doctrine/ORM/UnitOfWork.php#L1060

Probably fixed by 9b4c50e81ec03c34805b95e7d1cfafba500557ef, but test case is still needed to prevent regression.

I was able to reproduce the issue in a test which is fixed when running on master. Let me know if there is anything I need to alter or if you need a PR.

https://github.com/javabudd/doctrine2/commit/c08fd24d9712d5fa6590fc24efbaedcd52c11604

@javabudd Can you please send a PR with the test against master? That would help us prevent regression in future. Thanks.

I can confirm that by installing doctrine/orm (dev-master e1825e3) the initial problem I've described initially does not appear anymore. Thanks guys, you are awesome!

Thanks for confirmation, closing then. Master will soon become 2.6.0, stay tuned. 😎

Was this page helpful?
0 / 5 - 0 ratings

Related issues

weaverryan picture weaverryan  Â·  3Comments

doctrinebot picture doctrinebot  Â·  3Comments

Inmmelman picture Inmmelman  Â·  3Comments

alexander-schranz picture alexander-schranz  Â·  3Comments

dmaicher picture dmaicher  Â·  3Comments