omines / datatables-bundle

DataTables bundle for Symfony
https://omines.github.io/datatables-bundle/
MIT License
252 stars 113 forks source link

Doctrine ORMAdapter detach() causing duplicate records #175

Closed samvaughton closed 1 year ago

samvaughton commented 3 years ago

Hey,

Come across an issue where if I am doing doctrine flush operations in the same request as handling the callback for datatables it will duplicate all hydrated entities that are loaded.

The code in question causing this was added a few years back:

https://github.com/omines/datatables-bundle/commit/187bd14ee83488fce652e526e3efbf8491a3c58c

if (Query::HYDRATE_OBJECT === $this->hydrationMode) {
    $this->manager->detach($entity);
}

What was the reasoning behind it so I can understand context etc? If it's required then I can try and implement a workaround.

detach() on doctrine entities has always been a source of bugs if the behaviour is not fully understood. Even the doctrine documentation is incorrect on the behaviour of detach(). Please see https://github.com/doctrine/orm/issues/8007 as it wouldn't make sense for me to re-type it here.

tldr; the datatables bundle detaches any doctrine object that is has loaded, if a flush operation is performed it will duplicate the record. I am not sure if a persist is required as I have a few cascades and may have missed something.

Is the line referenced above required? It introduces potentially unwanted/unknown side effects if other doctrine operations are being performed within the same request.

If I am not being clear let me know, cheers.

curry684 commented 3 years ago

We detach the rows because otherwise your PHP blows up all the time when people try to paginate 500+ rows in a complex database with many eager joins, it's simply a memory preservation measure.

curry684 commented 3 years ago

Copying @shades684 in on this, he's more into Doctrine than me.

ellmout commented 3 years ago

Hi, The detach function will be remove in doctrine 3.0. I've got a lot of Depreciation notice for this.

Method Doctrine\ORM\EntityManager::detach() is deprecated and will be removed in Doctrine ORM 3.0.
curry684 commented 3 years ago

I don't mind removing it but we added it because in our initial use cases we actually ran into out-of-memory issues due to the entity manager blowing up.

We also don't formally support Doctrine 3.x yet (mostly for this reason).

curry684 commented 3 years ago

Fixed in #198

juaniAla commented 3 years ago

Hi guys, so with the revert of fix 198, what do I do with the duplicate rows? Is there a way to fix this?

curry684 commented 2 years ago

Not fixed yet.

shumik commented 2 years ago

Hello everyone! Any news on given topic?

github-actions[bot] commented 1 year ago

Stale issue message

github-actions[bot] commented 1 year ago

Stale issue message