Skip setting initialized readonly properties during refresh (#9505)#12496
Open
YoussefMansour9 wants to merge 2 commits into
Open
Skip setting initialized readonly properties during refresh (#9505)#12496YoussefMansour9 wants to merge 2 commits into
YoussefMansour9 wants to merge 2 commits into
Conversation
Member
That's cool and all, but you should still add a test that would fail without your patch. |
greg0ire
reviewed
Jun 4, 2026
| && $accessor instanceof ReadonlyAccessor | ||
| && $accessor->getUnderlyingReflector()->isInitialized($entity) | ||
| ) { | ||
| continue; |
Member
There was a problem hiding this comment.
🤔 if you just skip the initialization, and the date has been changed by another process, refresh just won't work, leading to bugs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9505
Problem
$em->refresh($entity)crashes withLogicExceptionwhen entity has readonly properties typed as objects (e.g.,DateTimeImmutable). During hydration,ReadonlyAccessor::setValue()compares old and new values by identity (!==). Different PHP object instances of the same logical value trigger the comparison and throw.Fix
In
UnitOfWork::createEntity(), skip callingsetValue()for fields whose accessor isReadonlyAccessorand whose property is already initialized on the entity during refresh.Testing