Uuid as a string type and updates without changes in the entity
sarven opened this issue · 2 comments
Description
I've described the problem here: https://sarvendev.com/2024/10/uuid-orm-and-strange-deadlocks/
Steps to reproduce
- create an entity with string $id, mapped as uuid_type
- save this entity
- get the entity from the database and try to save it without changes
- UoW treats this entity as changed because original data contains a Uuid object (returned from UuidType::convertToPHPValue), and the actual data in the entity object contains a string
UPDATE table SET id = '2082c2e5-9eb5-43c1-809e-82265da220f0' WHERE id = '2082c2e5-9eb5-43c1-809e-82265da220f0'
Expected behavior
UuidType always returns the same type, and it isn't possible to make such a mistake. UuidType::convertToDatabaseValue should probably only accept UuidInterface as a parameter. I was thinking about implementing that, but it's a breaking change, so I am not sure about that. Perhaps the same problem occurs also with other types. I've just created this issue to open the discussion on how it could be fixed.
Can you provide some code I can use to reproduce this issue? I've read the blog post and your steps here, but I want to make sure I'm able to fully reproduce the issue.
Thanks!
@ramsey I've just prepared a repository with a simple test to showcase this problem: https://github.com/sarven/uuid-bug-example/blob/main/tests/Repository/EntityRepositoryTest.php
UUID in the entity is represented as a string, it works, but during an update without any changes, it generates additional empty update.
UPDATE entities SET id = ? WHERE id = ?