fix: Do not change readonly id when deleting (#9538)#12416
fix: Do not change readonly id when deleting (#9538)#12416robske110 wants to merge 1 commit intodoctrine:3.6.xfrom
Conversation
Link for the lazy: 4212b88
I asked my LLM, it says that it's
And indeed, in the diff above, you can see that Line 1629 in 580a95c |
|
To answer to your comment regarding my additional notes: I think the reason the LLM provided doesn't really make sense.
We're actually using spl_object_id here (but it has the same reuse behavior). However, reuse can in my opinion not lead to additional bugs, as if the object id will be reused, that object obviously should also be initially in STATE_NEW - and that's now just still cached. Now re-reading the comments above the commented line, it actually explictly mentions this. Also: Because this project now requires PHP 8 this could all be rewritten to use a WeakMap anyways if we for some reason that's not yet obvious to me need/want to start storing the state again. This also gets rid of multiple "memory leaks", and the reuse "issue", but it would not solve the DETACHED state not being possible. And on that DETACHED state: |
|
Let me know if this PR otherwise looks good now with the simplified check, then I can squash the two commits together. |
If the identifier is a readonly attribute, we cannot set it to null. While this effectively prevents reuse of the object, skipping the setting allows to use readonly identifiers for entities that need to be removed.
Fixes #9538 by not resetting the ID of objects which have a readonly identifier to null.
This will cause those to not be seen as new objectes (will be STATE_DETACHED). However, this is in my understanding not a problem as entities with readonly ID cannot be reused anyways.
If those need to be seen as NEW for some practical reason, we could also persist the NEW state in entityStates (which the commented line just above the resetting does).
Additional notes:
From the commit commenting that line out, it is not entirely clear to me why that change was made (setting id to null rather than persisting the state). Persisting the state instead of setting the id to null does not seem to cause any trouble with all tests passing (apart from maybe a slight memory leak).
This does not touch the issues #9505.