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
[Form] DoctrineOrmTypeGuesser causes error for DecimalType #31905
Comments
This is expected behaviour. The |
Expected as it may be regarding the doctrine mapping, the transformer introduces a BC break here. In that case I would expect the transformer to pass when the value enters the transformer as a float. |
I would first investigate why your data is a float in the first place as it's probably even not guaranteed that it will work with Doctrine in all cases. As a quick workaround you can probably also add the |
Well, to the why it is a float is simple, the model says it is a float and the return type of the method as well as the declaration of the property is configured that way. I have in fact implemented the field with the number type in the form explicitly now so the pressure is off at the moment. But I’m interested to hear what others think. |
After discussing this with my colleague I tried to alter the type of my model from Decimal to Float and the following came to light: After: As long as the precision and scale are defined, the form enforces the values to meet these demands, however on database level these constraints are no longer present. |
See #32125 where we try to relax the data transformer. Does that help here? |
I think this will do the trick. Let me test this tomorrow |
…buh) This PR was merged into the 4.3 branch. Discussion ---------- [Form] accept floats for input="string" in NumberType | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #31905, #32124 | License | MIT | Doc PR | Commits ------- 2abf855 accept floats for input="string" in NumberType
Symfony version(s) affected: 4.3.0
Description
The TypeGuesser (DoctrineOrmTypeGuesser) sets the option input to string which causes the StringToFloatTransformer to take effect. Passing a float from the model to the form causes the transformation to fail
Possible Solution
Remove the option input: string from the TypeGuesser or allow values which are already a float to pass the transformer.
Why this option is added for a DecimalType (as a default) in the first place is a riddle to me.
The text was updated successfully, but these errors were encountered: