Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix changeset computation for enum arrays#10277

Merged
derrabus merged 1 commit into
doctrine:2.13.xfrom
michnovka:2.13.x-fix-enum-arrays-changeset
Dec 12, 2022
Merged

Fix changeset computation for enum arrays#10277
derrabus merged 1 commit into
doctrine:2.13.xfrom
michnovka:2.13.x-fix-enum-arrays-changeset

Conversation

@michnovka
Copy link
Copy Markdown
Contributor

Fix #10251


if ($orgValue instanceof BackedEnum) {
$orgValue = $orgValue->value;
if (! empty($class->fieldMappings[$propName]['enumType'])) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if somebody is interested why I added this check, its because I want to avoid the case where we have an array and go over the whole array checking if its BackedEnum for no reason. This way, unless there are enums in the play for the given field, no checks whatsoever are performed. Likely 0 performance gains with simple enums, but large performance gain with arrays of enums.

@michnovka
Copy link
Copy Markdown
Contributor Author

@greg0ire please review

@greg0ire
Copy link
Copy Markdown
Member

greg0ire commented Dec 8, 2022

Fix changeset computation for enum arrays

Please explain how it is broken, and what solution you applied in the commit message. I will review when that's done.

@michnovka
Copy link
Copy Markdown
Contributor Author

@greg0ire done

Comment thread lib/Doctrine/ORM/UnitOfWork.php Outdated
@greg0ire greg0ire added the Bug label Dec 8, 2022
@greg0ire
Copy link
Copy Markdown
Member

greg0ire commented Dec 8, 2022

@ThomasLandauer can you please test this?

Previously, array of enums were incorrectly compared in UoW::computeChangeSet() resulting always in false positive, since the original data for comparison is fetched using ReflectionEnumProperty::getValue(), which returns the enum values, not enum objects.
This fix ensures comparing the individual enum array members' values.
@michnovka
Copy link
Copy Markdown
Contributor Author

@ThomasLandauer can you please test this?

I have tested it on https://github.com/ThomasLandauer/doctrine-issue-10251 and it did fix the issue

@michnovka
Copy link
Copy Markdown
Contributor Author

can we add this on 2.13.5 milestone?

@greg0ire
Copy link
Copy Markdown
Member

greg0ire commented Dec 9, 2022

We usually do this right after merging.

@derrabus derrabus added this to the 2.13.5 milestone Dec 12, 2022
@derrabus derrabus merged commit bd11475 into doctrine:2.13.x Dec 12, 2022
derrabus added a commit to derrabus/orm that referenced this pull request Dec 12, 2022
* 2.13.x:
  Fix changeset computation for enum arrays (doctrine#10277)
  Psalm 5.2.0 (doctrine#10291)
  Run tools on PHP 8.2 (doctrine#10287)
derrabus added a commit to derrabus/orm that referenced this pull request Dec 12, 2022
* 2.14.x:
  Fix changeset computation for enum arrays (doctrine#10277)
  Psalm 5.2.0 (doctrine#10291)
  Run tools on PHP 8.2 (doctrine#10287)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UnitOfWork still not right - probably Enum-related

4 participants