UnitOfWork::executeUpdates iterates through an empty entityUpdates array #5803

Closed
opened 2026-01-22 15:18:20 +01:00 by admin · 9 comments
Owner

Originally created by @eugenmihailescu on GitHub (Dec 13, 2017).

Originally assigned to: @Majkl578 on GitHub.

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; }

Originally created by @eugenmihailescu on GitHub (Dec 13, 2017). Originally assigned to: @Majkl578 on GitHub. 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 <project-root-path>/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](https://github.com/doctrine/doctrine2/blob/v2.5.13/lib/Doctrine/ORM/UnitOfWork.php#L1053) 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](https://github.com/doctrine/doctrine2/blob/v2.5.13/lib/Doctrine/ORM/UnitOfWork.php#L1053) 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](https://github.com/doctrine/doctrine2/blob/v2.5.13/lib/Doctrine/ORM/UnitOfWork.php#L1060) 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](https://github.com/doctrine/doctrine2/blob/v2.5.13/lib/Doctrine/ORM/UnitOfWork.php#L1054): > if(0===count($this->entityUpdates)){ continue; }
admin added the BugMissing Tests labels 2026-01-22 15:18:20 +01:00
admin closed this issue 2026-01-22 15:18:20 +01:00
Author
Owner

@kmwalke commented on GitHub (Dec 14, 2017):

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

@kmwalke commented on GitHub (Dec 14, 2017): Came here to report this exact issue. Thanks for writing it up!
Author
Owner

@javabudd commented on GitHub (Dec 14, 2017):

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.

@javabudd commented on GitHub (Dec 14, 2017): 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.
Author
Owner

@Ocramius commented on GitHub (Dec 15, 2017):

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
.

@Ocramius commented on GitHub (Dec 15, 2017): 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> > . >
Author
Owner

@javabudd commented on GitHub (Dec 15, 2017):

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

@javabudd commented on GitHub (Dec 15, 2017): 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
Author
Owner

@Majkl578 commented on GitHub (Dec 16, 2017):

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

@Majkl578 commented on GitHub (Dec 16, 2017): Probably fixed by 9b4c50e81ec03c34805b95e7d1cfafba500557ef, but test case is still needed to prevent regression.
Author
Owner

@javabudd commented on GitHub (Dec 17, 2017):

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.

c08fd24d97

@javabudd commented on GitHub (Dec 17, 2017): 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
Author
Owner

@Majkl578 commented on GitHub (Dec 17, 2017):

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

@Majkl578 commented on GitHub (Dec 17, 2017): @javabudd Can you please send a PR with the test against master? That would help us prevent regression in future. Thanks.
Author
Owner

@eugenmihailescu commented on GitHub (Dec 18, 2017):

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!

@eugenmihailescu commented on GitHub (Dec 18, 2017): 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!
Author
Owner

@Majkl578 commented on GitHub (Dec 18, 2017):

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

@Majkl578 commented on GitHub (Dec 18, 2017): Thanks for confirmation, closing then. Master will soon become 2.6.0, stay tuned. 😎
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5803