DDC-3622: [GH-1336] Fix UoW warning with custom id object types #4451

Closed
opened 2026-01-22 14:41:53 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Mar 17, 2015).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user @doctrinebot:

This issue is created automatically through a Github pull request on behalf of stefanotorresi:

Url: https://github.com/doctrine/doctrine2/pull/1336

Message:

UnitOfWork::tryGetById() and UnitOfWork::tryGetByIdHash() may receive an object as an id, for instance when using a custom id type like Rhumsaa\Uuid.

This PR adds a simple cast to string in these methods.

There are a couple of things I'm not sure about, tho.

First of all, I don't know if functional tests alone are deemed sufficient, but I couldn't figure out how to replicate the issue via unit tests only (apart from directly invoking the two methods above with an object as argument, which looks a bit pointless).

Furthermore, I don't know if the cast should be applied elsewhere; so far the only cases I stumbled upon where common find and fetch joins, but I saw other methods where it may be necessary (i.e. here and here), but I couldn't replicate the code path to reach those.
Also I wonder if an exception should be thrown if the id object doesn't implement **toString(), and in this case if the fix should be refactored into Doctrine\ORM\Utility\IdentifierFlattener, for a bit of SoC.

Let me know what you think.

Originally created by @doctrinebot on GitHub (Mar 17, 2015). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user @doctrinebot: This issue is created automatically through a Github pull request on behalf of stefanotorresi: Url: https://github.com/doctrine/doctrine2/pull/1336 Message: `UnitOfWork::tryGetById()` and `UnitOfWork::tryGetByIdHash()` may receive an object as an id, for instance when using a custom id type like [Rhumsaa\Uuid](https://github.com/ramsey/uuid/blob/2.8.0/src/Doctrine/UuidType.php). This PR adds a simple cast to string in these methods. There are a couple of things I'm not sure about, tho. First of all, I don't know if functional tests alone are deemed sufficient, but I couldn't figure out how to replicate the issue via unit tests only (apart from directly invoking the two methods above with an object as argument, which looks a bit pointless). Furthermore, I don't know if the cast should be applied elsewhere; so far the only cases I stumbled upon where common find and fetch joins, but I saw other methods where it may be necessary (i.e. [here](https://github.com/doctrine/doctrine2/blob/878f2455eee79f1573d2bb1f8c01be93f758779b/lib/Doctrine/ORM/UnitOfWork.php#L1559) and [here](https://github.com/doctrine/doctrine2/blob/878f2455eee79f1573d2bb1f8c01be93f758779b/lib/Doctrine/ORM/UnitOfWork.php#L1625)), but I couldn't replicate the code path to reach those. Also I wonder if an exception should be thrown if the id object doesn't implement `**toString()`, and in this case if the fix should be refactored into `Doctrine\ORM\Utility\IdentifierFlattener`, for a bit of SoC. Let me know what you think.
admin added the Bug label 2026-01-22 14:41:53 +01:00
admin closed this issue 2026-01-22 14:41:53 +01:00
Author
Owner

@doctrinebot commented on GitHub (Mar 17, 2015):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1336] was closed:
https://github.com/doctrine/doctrine2/pull/1336

@doctrinebot commented on GitHub (Mar 17, 2015): Comment created by @doctrinebot: A related Github Pull-Request [GH-1336] was closed: https://github.com/doctrine/doctrine2/pull/1336
Author
Owner

@doctrinebot commented on GitHub (Mar 17, 2015):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Mar 17, 2015): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4451