-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Invalid value "" for ENUM #173
Comments
Have you added the next line into your entity? use Fresh\DoctrineEnumBundle\Validator\Constraints as DoctrineAssert; I see it is missed in your example. But maybe you deleted it to make your code snippet shorter. Anyway I need to clarify, that you don't forget to include this validation constraint for you entity. |
Indeed, I have correctly imported the right constraint and missed to add it in my previous post after cleaning up a little bit my entity. (I edited the previous message to include the missing parts) |
Please add config for Doctrine in your project |
# config/packages/doctrine.yaml
doctrine:
dbal:
types:
security_permission: App\PermissionEnum
orm:
auto_generate_proxy_classes: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true The type is working well when bound to my entity field since it generate a good SQL migration. |
And if override the method public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
return $value;
} It works as expected and my validation constraint is well executed. |
Can you debug |
The validation process happen after the execution of So if the method throws an exception, which is the case in the implementation of It is the same for all validations rules bound to a field which is an ORM Column of the type In my opinion, it must not throw exception in convertToDatabaseValue and let the users check if the values are in the Enum set through the validation rule. Or catch the exception and handle it during the validation process. |
Very strange. I've checked your cases in my code. I cannot reproduce it. If I set a wrong value, it is being catched by validator. I never reach the |
I'm using API Platform on top of that, which could be the cause...
I don't know how it is handled internally when creating entities through API Platform endpoint. Maybe it calls the type class before the validation. ATM, my 'fix' by overriding the |
@TZK- I have to reproduce this bug with api-platform/api-pack. Right now I cannot reproduce it on my own projects |
Hi, I have the same problem with API-Platform 2.6. When filtering, if the value in not correct, it throws an error instead of returning a validation error. |
I have an error when trying to set a value in my entity which is not part of my enum.
In my entity, I set a validation constraint to ensure that values must one of the enum.
Howewer, It always throws InvalidArgumentException when it calls AbstractEnumType::convertToDatabaseValue() after I try to insert a new record in my database with a value which is not in the enum.
I do not really understand why convertToDatabaseValue() method throws an exception in this case since I want the validation constraint being called first.
Am I doing something wrong ?
The text was updated successfully, but these errors were encountered: