Regression: custom types seem to be overridden since 4.3.0
Bug Report
| Q | A |
|---|---|
| Version | 4.3.* |
| Previous Version if the bug is a regression | 4.2.* |
Summary
Since DBAL 4.3.0, the test suite for brick/geo-doctrine started failing:
https://github.com/brick/geo-doctrine/actions/runs/17490924621/job/49680343915
Doctrine\DBAL\Exception\InvalidColumnDeclaration: Column "geometry" has invalid type ... Doctrine\DBAL\Exception\InvalidColumnType\ColumnLengthRequired: Doctrine\DBAL\Platforms\MySQL80Platform requires the length of a VARBINARY column to be specified
Types are added this way:
use Doctrine\DBAL\Types\Type;
Type::addType('Geometry', Types\GeometryType::class);
And used as:
#[ORM\Column(type: 'Geometry')]
public Geometry $geometry;
It looks like since version 4.3.0, the GeometryType is overridden at some point with BinaryType.
git bisect tells me that the culprit is a07b35ca50a128c2daaba61e4065dd8f5d10ed49.
Note: the test suites of brick/date-time-doctrine and brick/phonenumber-doctrine did pass with DBAL 4.3.3, so this may be specific to types mapping to binary columns.
@BenMorel please try to reproduce the issue by using only the DBAL. I could reproduce the failure when running the test suite locally but only if the entire suite runs. If I run the failing test alone, it passes:
DB_DRIVER=pdo_mysql ... phpunit tests/Types/LineStringTypeTest.php
Database version: 9.4.0
Database platform: Doctrine\DBAL\Platforms\MySQL84Platform
PHPUnit 10.5.55 by Sebastian Bergmann and contributors.
Runtime: PHP 8.4.12
Configuration: /Users/morozov/Projects/geo-doctrine/phpunit.xml
. 1 / 1 (100%)
Time: 00:00.101, Memory: 12.00 MB
OK (1 test, 15 assertions)
Maybe unrelated, but I also got this behavior for a custom MoneyType that extends the StringType. This exception is thrown even when the "length" is defined in the metadata / mapping...
As a quick fix I introduced an intermediate class which sets a default length:
abstract class DefaultLengthStringType extends StringType
{
/**
* For some reason the "length" property is not respected properly in Doctrine XML Metadata for custom types...
*/
public function getSQLDeclaration(array $column, AbstractPlatform $platform) : string
{
$column['length'] ??= 255;
return parent::getSQLDeclaration($column, $platform);
}
}
Maybe unrelated, but I also got this behavior for a custom
MoneyTypethat extends theStringType. This exception is thrown even when the "length" is defined in the metadata / mapping...As a quick fix I introduced an intermediate class which sets a default length:
abstract class DefaultLengthStringType extends StringType { /** * For some reason the "length" property is not respected properly in Doctrine XML Metadata for custom types... */ public function getSQLDeclaration(array $column, AbstractPlatform $platform) : string { $column['length'] ??= 255;
return parent::getSQLDeclaration($column, $platform); }}
same for 4.3.4, custom types with length defined, still getting error "Doctrine\DBAL\Platforms\MySQL80Platform requires the length of a VARCHAR column to be specified", while debugging occured that custom type is reason