-
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
Incorrect Mapping of BackedEnum #10077
Comments
Can you provide a test case for this? |
Same issue for me. The enum is constructed from a string twice in the hydration process, leading to this error the second time. The first time in this function https://github.com/doctrine/orm/blob/2.13.2/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php#L407 and the second time here https://github.com/doctrine/orm/blob/2.13.2/lib/Doctrine/ORM/UnitOfWork.php#L2745. |
This issue is introduced with 2.13.2, 2.13.1 works fine. |
It is probably related to #10041. @michnovka Any ideas why this happens? |
Hello, I have the same issue. It is already fixed in |
I fix this issue by changing /**
* @param object $object
* @param int|string $value
*/
private function initializeEnumValue($object, $value): BackedEnum
{
$enumType = $this->enumType;
try {
// Check if value already is instance of $enumType return it, else get value from $enumType
if($value instanceof $enumType){
return $value;
}
return $enumType::from($value);
} catch (ValueError $e) {
throw MappingException::invalidEnumValue(
get_class($object),
$this->originalReflectionProperty->getName(),
(string) $value,
$enumType,
$e
);
}
} |
I can confirm this 😄 |
Hi, al! I updated symfone application from 6.1.3 to 6.1.5 where doctrine/orm has been updated from 2.13.1 to 2.13.2. I found where this bug occurs \Doctrine\ORM\Mapping\ReflectionEnumProperty::setValue() was
I corrected as
and it all worked. |
@devtronic Nothing stops you from simply adding |
@devtronic I gave an estimate, don't tell me you're going to treat it as a deadline? Who are you, a project manager? |
This also fundamentally broke several of my production environments overnight today. While the conflict workaround is fine of course I do think the severe impact of this bug warrants actually yanking the 2.13.2 release - I upgraded 3 days ago while the cause was determined 7 days ago, I wouldn't have been affected had it been yanked. |
I don't think we can do that if people not affected by this bug are referring to that release in their |
Very, very soon: https://github.com/doctrine/orm/releases/tag/2.13.3 |
Thank you @greg0ire and everyone involved for your effort and the quick fix! |
Only if someone already changed the definition to edit: and thanks for the new release :) |
Will consider it next time, thanks 👍 |
Bug Report
doctrine/orm/lib/Doctrine/ORM/Mapping/ReflectionEnumProperty.php is not able to inizialize enum from its value
Summary
in version 3.4.4 BackedEnum are mapped correctly
Current behaviour
"App\\Enum\\VatClassEnum::from(): Argument doctrine/dbal#1 ($value) must be of type string, App\\Enum\\VatClassEnum given"
basilicaly the value of $value should be a string not a BackeEnum
How to reproduce
backed enum
enum VatClassEnum : string { case I = 'I'; case C = 'C'; }
create an entity with the following field
#[ORM\Column(length : 4, nullable : true, enumType : VatClassEnum::class)] private ?VatClassEnum $vatClass = null;
Expected behaviour
correct hydratation of entity
The text was updated successfully, but these errors were encountered: