Calling computeChangeSets from onUpdate Entity listener #6219

Closed
opened 2026-01-22 15:29:06 +01:00 by admin · 1 comment
Owner

Originally created by @ghost on GitHub (Apr 14, 2019).

Originally assigned to: @Ocramius on GitHub.

Q A
Version ~2.4

Question

Hello, I've got some question about internals of UnitOfWork.

The problem is when I got both Entity lifecycle callback and listener for onUpdate event -- if the state of Entity is somehow changed and then UnitOfWork::computeChangeSets() is called from the listener, I loose all changes except those made by lifecycle callback.

Is it wrong to call computeChangeSets() from Entity listener, and, if not, should not it calculate changesets correctly?

To reproduce this (probably bug), I created a repository

I appreciate any response to my problem!

Originally created by @ghost on GitHub (Apr 14, 2019). Originally assigned to: @Ocramius on GitHub. | Q | A |------------ | ----- | Version | ~2.4 ### Question Hello, I've got some question about internals of `UnitOfWork`. The problem is when I got both Entity lifecycle callback and listener for `onUpdate` event -- if the state of Entity is somehow changed and then `UnitOfWork::computeChangeSets()` is called from the listener, I loose all changes except those made by lifecycle callback. Is it wrong to call `computeChangeSets()` from Entity listener, and, if not, should not it calculate changesets correctly? To reproduce this (*probably bug*), I created a [repository](https://github.com/ecenti/scratch-app) I appreciate any response to my problem!
admin added the Question label 2026-01-22 15:29:06 +01:00
admin closed this issue 2026-01-22 15:29:06 +01:00
Author
Owner

@Ocramius commented on GitHub (Apr 14, 2019):

Is it wrong to call computeChangeSets() from Entity listener, and, if not, should not it calculate changesets correctly?

Yes: please act in onFlush and use recompute* methods instead.

@Ocramius commented on GitHub (Apr 14, 2019): > Is it wrong to call `computeChangeSets()` from Entity listener, and, if not, should not it calculate changesets correctly? Yes: please act in `onFlush` and use `recompute*` methods instead.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6219