[PR #1336] Fix UoW warning with custom id object types #9391

Closed
opened 2026-01-22 16:04:11 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/1336

State: closed
Merged: No


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.

**Original Pull Request:** https://github.com/doctrine/orm/pull/1336 **State:** closed **Merged:** No --- `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 pull-request label 2026-01-22 16:04:11 +01:00
admin closed this issue 2026-01-22 16:04:11 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#9391