Closed j0r1s closed 2 years ago
Can you try to modify the file like this?
- ->setParameter($parameterName, $value);
+ ->setParameter($parameterName, $value->getId()->toBinary());
We could add a check if instanceof AbstractUuid or AbstractUlid, -> toBinary()
yes it's working with $value->getId()->toBinary()
We could check for $value->getId() instance of AbstractU[ul]id but how one could guess that the primary key is $id
? This is conventional and not mandatory, right ?
Lets wait for @javiereguiluz here
Sorry, I don't use UUIDs for entity IDs ... so I don't know how to properly fix this or even if we can fix this without breaking the existing behavior. Sorry!
@j0r1s I am using UUIDs and I can't reproduce this bug. Which version of EasyAdmin are you using ?
EDIT: My setup differs from yours, that's why I don't have the same behavior.
Are you using a UUID as string or an object?
As a string, here's my IdTrait
trait IdTrait
{
/**
* @ORM\Id
* @ORM\Column(type="string")
* @ORM\GeneratedValue(strategy="UUID")
*/
protected $id;
/**
* @return string
*/
public function getId()
{
return $this->id;
}
}
I'm not using the new doctrine type. And I'm using UUID v1, not v4.
Ok yes this is working, but not using a Uid as object ππ»
Ok yes this is working, but not using a Uid as object ππ»
Yes exactly ! My UUIDs are stored as binary objects, and Doctrine is querying for the string representation.
In my project, I've solved the issue by creating a custom UuidEntityFilter
that casts the parameter to its binary form.
Afterall I'm wondering if this could be an issue that belongs to Symfony since I've had to edit some of my classics (not EA) repository methods for the queries to work. The worst part is that it fails silently, the queries just return no result.
Anyone willing to investigate if we could "fix" (or "improve") this in EasyAdmin? Maybe we can add some "isBinary()" check somewhere to transform UUIDs into strings, if needed, when performing some query. Thanks!
Anyone willing to investigate if we could "fix" (or "improve") this in EasyAdmin? Maybe we can add some "isBinary()" check somewhere to transform UUIDs into strings, if needed, when performing some query. Thanks!
@javiereguiluz I will also take a look sone, as I am building a new project using symfony/uid
π
In my project, I've solved the issue by creating a custom UuidEntityFilter that casts the parameter to its binary form.
@j0r1s what about adding a check to the EntityFilter
so we have a generic entry point for this?
Can you try if this works in your project by modifiying the vendor code?
Any updates? I'm currently working on a project with symfony/uid
and could see the described behavior also on my side.
I am trying to find a universal solution for the "isBinary()" check of the value
Hi @OskarStark , are still planning to work on this issue? If not then I would try to have a closer look on this.
Hi, I don't have some time to jump on this right now, sorry
I created a reproducer: https://github.com/michaelKaefer/easy-admin-reproducer/tree/issue/4125 (and a PR).
I just wanted to add that I'm using v4.0.1
but the fix doesn't seem to work for me. Instead of OPs UuidV4Generator
, I'm using UuidOrderedTimeGenerator
from ramsey/uuid-doctrine for my identifiers.
@ToshY Yes, the fix was meant for symfony/uid
and is not working for ramsey/uuid-doctrine
. I am not sure but I guess if you want to use ramsey/uuid-doctrine
you have to implement everything you need in your app. I guess that the maintainers do not want to support every UUID implementation but I am not sure, maybe a PR would be accepted.
Just because I am curious, do you think you could switch to symfony/uid
for your use case?
@michaelKaefer Well I could definitely switch as I'm just starting a new project. The thing is that I already used ramsey/uuid
and ramsey/uuid-doctrine
in other Symfony projects (without EasyAdmin), so I was under the impression that something like that would also be supported. Dangerous assumption in hindsight.
Guess it makes sense to refrain from supporting lots of UUID implementations, but it's also worth noting that symfony/uid
"does not replace full-featured libraries such as ramsey/uuid". Correct me if I'm wrong, but with ramsey/uuid
being the most popular library in this regard, maybe adding support wouldn't hurt?
@ToshY Thanks for the infos! - I don't know, maybe a PR is welcome but supporting a lot of packages means that the maintainers have to maintain a lot of code.
We are also using ramsey/uuid and ran into the same issue. We will investigate a fix and submit a PR.
If I am not mistaken, the following code eventually makes use of the doctrine types, which is why a single added line would make it work for Ramsey/uuid, seeing it is also using uuid as the doctrine type name:
if (('uuid' === $identifierType && $identifierValue instanceof Uuid)
|| ('ulid' === $identifierType && $identifierValue instanceof Ulid)
|| ('uuid' === $identifierType && $identifierValue instanceof Ramsey\Uuid)) {
Which is why I am wondering what the added value is of limiting the code to specific UUID or ULID classes.
Why not remove this restriction and go for the following?
if ('uuid' === $identifierType || 'ulid' === $identifierType) {
try {
return Type::getType($identifierType)->convertToDatabaseValue($identifierValue, $entityManager->getConnection()->getDatabasePlatform());
} catch (\Throwable $exception) {
// if the conversion fails we cannot process the uid parameter value
return $parameterValue;
}
}
Describe the bug I have entities identified by uuids, the
EntityFilter
is not filtering them properly and returns no result.To Reproduce I've recreated a blank project and I'm able to reproduce the bug following those steps :
Then I'm creating two simple entities identified by uuids with custom generators UuidV4, following this symfony blog post.
Configuring EA :
Then I'm creating a category via EA crud, and a book with this category associated.
(OPTIONAL) Additional context
src/Entity/Book.php
src/Entity/Category.php
src/Controller/Admin/BookCrudController.php
I'm not adding other files (DasboardController / CategoryCrudController) since their configuration is trivial.
I've investigated EA code and found that if I add those modifications to
vendor/easycorp/easyadmin-bundle/src/Filter/EntityFilter.php
The filtering works fine, I have no idea how to fix this "properly" in a backward compatible way with classical auto-increment strategies.