mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Lazy Ghost Proxy Hydration Overwrites Local Entity Changes #7490
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 @ilianiv on GitHub (Mar 26, 2025).
Bug Report
Summary
Proxy hydration overwrites local entity changes, potentially causing data inconsistencies.
Current behavior
In a setup with Employee and Car entities having a OneToOne bidirectional relationship, where Employee is the owning side with car_id in the database, and Car has an is_free boolean indicating its association status:
To detach a Car from an Employee, the following steps are undertaken:
After these steps, Car::$employee unexpectedly becomes non-null.
Expected behavior
Hydration should not overwrite existing properties in a lazy-ghost proxy to prevent unintentional data loss.
Maybe there should be a mechanism that prevents local modifications to lazy-ghost proxies before they are hydrated.
How to reproduce
https://github.com/ilianiv/lazy-ghost-issue
@beberlei commented on GitHub (Mar 29, 2025):
@ilianiv in Step 4 you write "(This does not trigger hydration since Car::$employee is part of the lazy proxy.)" - Cann you clarify what you mean by that?
@ilianiv commented on GitHub (Mar 31, 2025):
I mean that the field
employeeis already assigned to the Car entity, despite the fact that the Car is still an uninitialized proxy. This is likely an optimization as the Car entity was retrieved via the Employee<->Car association. This behavior prevents the hydration skipping the magic getter (LazyGhostTrait::__get)@ilianiv commented on GitHub (May 8, 2025):
Hello, @beberlei!
I've tried updating to doctrine/orm@3.3.3 but this problem still exists.
Can you confirm that this is not the intended behavior and have you been able to replicate it?