-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[UId/Doctrine] Entity repository error "ConversionException" #38929
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
Comments
Shouldn't this be an instance of |
@nicolas-grekas you mean using? // $uuid is 'e2e64173-174b-4109-a3ce-971a1e9d3b56'
$uuid = Uuid::fromString($uuid); I will try this, thank you for your answer |
@nicolas-grekas works fine, many thanks |
@nicolas-grekas Hi Nicolas. Even though the original poster closed this thread having found a workaround, I do think he was on to something. I'm currently struggling with a broken ParamConverter on 5.2.0-BETA3, and while I don't fully understand the specifics of it, I think it has to do with your PR #38605. In a standard controller (created via make:crud), the DoctrineParamConverter will not transform the UUID string from the route parameter to a Uid object before passing it to EntityRepository::find. After that, a string won't be accepted any more as input, and the AbstractUidType will throw a conversion exception. I'm not sure though if this has to be fixed in the ParamConverter, in Doctrine/DBAL, or in the AbstractUidType. I'm also not sure if anything on my project is wonky (if it helps, I'll set up a minimal example to reproduce) - but I only noticed the behavior after upgrading to BETA3. Package versions (excerpt) are as follows: doctrine/common 3.0.2 |
Thanks for the feedback @lars-feyerabend, I missed this use case when I submitted #38605
Anyone else has an opinion on this? @stof maybe? |
I've looked into this a bit more. Reverting the change in AbstractUidType to be more lenient regarding its input in convertToDatabaseValue would make it consistent with ramsey's implementation in ramsey/uuid-doctrine. It would, however, not be consistent with Doctrine's standard types, which seem to apply the more strict input handling (e. g., see \Doctrine\DBAL\Types\DateImmutableType). ParamConverters exhibit the same problem for the DateImmutableType (I've set up a test repo here: https://github.com/lars-feyerabend/symfony-issue-38929), the string value from the URL is never converted to DateTimeImmutable. Also, without a matching type guesser and form type (with a data transformer applied) UUID fields in forms don't work due to the same change. However, when using EntityType to define a relation to a different entity, it works, I guess because the field's value is set to the other entity's So I guess if I had to state an opinion, I'd say short-term solution is reverting the change in AbstractUidType, long-term solution is having a deeper look into the relationship between ParamConverter and EntityRepository. |
Please try #38986 |
…lues (nicolas-grekas) This PR was merged into the 5.2-dev branch. Discussion ---------- [DoctrineBridge] accept converting Uid-as-strings to db-values | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #38929 | License | MIT | Doc PR | - In #38605 I made Uid types stricter by taking inspiration from native Doctrine types. But #38929 (comment) made me realize this doesn't work with ParamConverters. Here is the fix. Commits ------- 20714d6 [DoctrineBridge] accept converting Uid-as-strings to db-values
Symfony version(s) affected: 5.2.0-beta3
Description
Entity repository failed to retrieve an entity with an Uid property with method
findOneBy
How to reproduce
See code after
Possible Solution
If I replace the doctrine
findOneByUuid
with a personal repo methodfindMyHumidorWithUuid
it works.Additional context
I am using Messenger and pass the object uuid to the async logic, then inside the handler I am trying to retrieve the original object, and the error occurs.
Some code:
Failure code:
See stack trace (inside a controller reproducer)
Working code:
It is linked to Doctrine of course, but as the UidType logic is inside Symfony I opened the issue here
Thank you
The text was updated successfully, but these errors were encountered: