Issue Feature Needs Feedback Orphaned

#107116Validate extbase domain model properties against DB schema limits

Torben Hansen 07/20/25, 17:50 updated 05/12/26, 07:58

Description

When you have an extbase application, which persists data, it is currently easily possible to crash the application when saving data to the persistence layer using extbase domain models and repositories. When the domain model for example has a field named title, which is defined in TCA as type input, TYPO3 will automatically create a varchar(255) DB field. When the extbase application however provides an input field to modify the title field, it is not checked, if the given data exceeds the defined DB field size. Instead, a hard Data too long for column 'title' at row 1 exception is thrown, if the provided data is too long for the database field.

Using the TcaSchemaFactory and the SchemaManager, it should be possible to determine possible DB schema field limits for domain model properties. A possible new feature (e.g. validator which is automatically applied to domain model validation) could check, if the given data with exceed DB schema field limits and add a validation error instead.

Example Validator code:

    public function __construct(private readonly DataMapFactory $dataMapFactory) {}

    public function isValid(mixed $value): void
    {
        if (!($value instanceof AbstractDomainObject)) {
            return;
        }

        /** @var TcaSchemaFactory $tcaSchemaFactory */
        $tcaSchemaFactory = GeneralUtility::makeInstance(TcaSchemaFactory::class);

        $dataMap = $this->dataMapFactory->buildDataMap(get_class($value));
        $schema = $tcaSchemaFactory->get($dataMap->getTableName());
        $schemaManager = GeneralUtility::makeInstance(ConnectionPool::class)
            ->getConnectionForTable($dataMap->tableName)
            ->createSchemaManager();
        $columns = $schemaManager->listTableColumns($dataMap->tableName);

        foreach ($schema->getFields() as $field) {
            if (!$field->isType(TableColumnType::INPUT)) {
                continue;
            }

            $fieldValue = $value->_getProperty($field->getName());
            $schemaColumn = $columns[$field->getName()] ?? null;

            if ($schemaColumn && strlen($fieldValue) > $schemaColumn->getLength()) {
                $this->addError('Field too long', 1753032690);
            }
        }
    }

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

Fix this issue

Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". How to create a patch

Commit message
[FEATURE] Validate extbase domain model properties against DB schema limits Resolves: #107116 Releases: main