-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix change set computation with enums #10074
Fix change set computation with enums #10074
Conversation
This is a good fix. I think |
See #10088 |
@derrabus this is an important fix for enums, can we have it merged for the next 2.13 point release? |
Thank you @HypeMC. |
* 2.14.x: Allow doctrine/event-manager 2 (doctrine#10123) Psalm 4.29 (doctrine#10128) Address deprecation of Table::changeColumn() (doctrine#10121) Make code blocks consistent (doctrine#10103) Fix change set computation with enums (doctrine#10074) PHPStan 1.8.8, Psalm 4.28.0 (doctrine#10115) fix deprecated trigger help comment
Is there an e.t.a. on a new release with this fix please? |
if ($orgValue instanceof BackedEnum) { | ||
$orgValue = $orgValue->value; | ||
} | ||
|
||
// skip if value haven't changed | ||
if ($orgValue === $actualValue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is broken, and I'm pretty sure this is why. Based on the changes in line 747, we probably also need to have:
if ($actualValue instanceof BackedEnum) {
$actualValue = $actualValue->value;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don think so. Check the code a bit above:
then
So actual value is fetched through reflection. And if you check the ReflectionEnumProperty::getValue()
It returns the $enum->value
already. Therefore your proposed
if ($actualValue instanceof BackedEnum) {
$actualValue = $actualValue->value;
}
seems redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be wrong. All I know is that this patch broke several of our entities that use enums, and that seemed like a possibility. I haven't tested the theory.
Fixes #10071 , uses test cases from #10073 by @mzk
My attempt at solving the issue. The
ReflectionEnumProperty::getValue()
method returns the value of the enum, while some hydrators pass an enum object in the data set to theUnitOfWork::$originalEntityData
array.The
SimpleObjectHydrator
doesn't convert strings into enums, while theObjectHydrator
(or to be more precise theAbstractHydrator::gatherRowData()
method) does. Even though this doesn't seem to be causing any issues, the inconsistency seems unintentional to me, so if you think it should be fixed please let me know and I'll open a PR.