-
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
Doctrine ORM 2.17.x Update Causes TypeError with indexBy on Doctrine Type (custom UUID) #11149
Comments
@mkarolczyk hey 👋 I tried finding what may have caused this, and failed, so instead, I wrote this blog post especially for you. Can you please try to apply what you read here to this issue, and let me know if anything is unclear? Thanks. |
Got same error after trying to use Optimized eager fetch instead of Multi-step hydration
|
OK. @beberlei can you please look into this? |
Did the git bisect thing (thanks @greg0ire working link to blog post) ... was introduced in 76fd34f76607b1b96f381377c1c51df292c759aa |
Nice job! The link did change since I published the blog post 😅 |
The other thing that might help would be a stack trace. Here is a documentation article (that I also authored) about that |
Here's a stack trace, It's happening at logon, with a chain of fetch='EAGER' relationships on OneToMany, ManytoOne then another OneToMany. Each entity has Symfony UUID PKs as below: #[ORM\Column(type: 'uuid')]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator('doctrine.uuid_generator')]
#[ORM\Id]
private ?Uuid $uuid = null; |
Related to #11097. The changes in this commit started injecting entities and backed enumerations as keys for collections. orm/lib/Doctrine/ORM/UnitOfWork.php Lines 3199 to 3204 in 76fd34f
In the example of #11097, it expects the scalar value behind the database column In the example by @rik702 above, it expects the scalar value behind the Uuid class, but gets the Uuid class/entity instead. In my beliefs the mapper in UnitOfWork should cast the result of @greg0ire any thoughts on this? |
No thoughts, this sounds good.
|
Hi everyone, I've been debugging, and I believe I've identified the issue. It appears that Doctrine ORM does not support arrays with custom types. You can find more information about this in the Doctrine ORM source code here: https://github.com/doctrine/orm/blob/b187bc85881cc85d36b28e7ed9dbe2071d472e30/src/Persisters/Entity/BasicEntityPersister.php#L1891 While the input contains the correct type, the output always seems to be translated to DBAL ArrayParameterType[STRING|INTEGER|ASCII]. In my case, the custom type (UuidType) is being translated to ArrayParameterType::STRING, which invokes Uuid::__toString() instead of using UuidType::convertToDatabaseValue() |
BC Break Report
Summary
After updating doctrine/orm to version 2.17.x, the index-by for doctrine type stopped working even though the object (custom UUID) has the __toString() method. Up to version 2.16.x everything worked fine.
TypeError: Doctrine\Common\Collections\ArrayCollection::set(): Argument #1 ($key) must be of type string|int, App\Common\Domain\Uuid given, called in /home/xxx/vendor/doctrine/orm/lib/Doctrine/ORM/PersistentCollection.php on line 191
Previous behavior
Until version 2.16.x, indexBy for doctrine type objects (custom UUID) with the __toString() method worked fine.
Current behavior
Currently, Doctrine is unable to read such an object and shows an error. Before creating an ArrayCollection, there is no cast to a simple type, in this case string.
TypeError: Doctrine\Common\Collections\ArrayCollection::set(): Argument #1 ($key) must be of type string|int, App\Common\Domain\Uuid given, called in /home/xxx/vendor/doctrine/orm/lib/Doctrine/ORM/PersistentCollection.php on line 191
How to reproduce
The text was updated successfully, but these errors were encountered: