Description
Symfony version(s) affected: 4.3
Description
I have the follow entity and field definition:
class Product
{
/**
* @ORM\Column(type="decimal", precision=10, scale=2)
*/
private $price = 0;
public function getPrice(): float
{
return $this->price;
}
public function setPrice(float $price)
{
$this->price = $price;
}
}
and a form field whose "type" is being guessed by DoctrineOrmTypeGuesser
:
$builder->add('price');
this works well before 4.3, but after upgrade this app, when the form is being built, this error appears:
Unable to transform data for property path "price": Expected a numeric string.
Possible Solution
It will depend on the right way of type-hinting decimal
fields.
Even if #30893 helps to solve a real problem with Doctrine's change detection, I think we must fix the BC break, either relaxing the transformation constraint allowing numeric values:
-if (!\is_string($value) || !is_numeric($value)) {
- throw new TransformationFailedException('Expected a numeric string.');
+if (!\is_numeric($value)) {
+ throw new TransformationFailedException('Expected a number or a numeric string.');
}
or reverting the change in DoctrineOrmTypeGuesser
:
symfony/src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php
Lines 77 to 78 in 030396a
deprecating this default, for later change in 5.0 to
input = string
.
WDYT?