mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Proxy tries to call destructor of not loaded entities, including removed entities #6173
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @arnaud-lb on GitHub (Feb 9, 2019).
Originally assigned to: @Ocramius on GitHub.
Bug Report
Summary
When an entity defines a destructor, an entity proxy will attempt to call the entity's destructor when it's destroyed.
Current behavior
If the proxy never initialised (it never loaded the actual entity), it will apparently try to load the entity during
__destruct.If the entity had been
removed(), we may see some unexpected behaviours or some EntityNotFoundException exceptions.How to reproduce
I've created a failing test case here:
db8cfd9d25Expected behavior
Should a proxy destructor attempt to load the entity if it's not already loaded ?
@Ocramius commented on GitHub (Feb 9, 2019):
Yes, it should still call the destructor
@arnaud-lb commented on GitHub (Feb 11, 2019):
I'm genuinely interested in hearing the rationale behind this.
Intuitively, I would have though that since the entity is not constructed yet, calling its destructor is not necessary, especially since this requires to construct it just for this purpose.
This would be sad, because apart from this bug, this also defeats the purpose of a lazy loading proxy: Entities with a destructor will always be loaded when its proxy/reference is destroyed.
@Ocramius commented on GitHub (Feb 11, 2019):
I've detailed this in following pre-existing issues (sorry, different repository, but same reasoning applies):
Correct.