dbal icon indicating copy to clipboard operation
dbal copied to clipboard

Schema manager errors on custom MySQL index

Open dbu opened this issue 10 months ago • 3 comments

Bug Report

Q A
Version 3.9.4

Summary

With a custom calculated index, the schema tool fails with an exception:

Argument #1 ($column) must be of type string, null given, called in /www/vendor/doctrine/dbal/src/Schema/Index.php on line 72

The index i created is CREATE INDEX json_author ON auction_json_indexed ( (JSON_VALUE(item, '$.author' RETURNING CHAR(255))) )

Current behavior

Exception trace:
  at /www/vendor/doctrine/dbal/src/Schema/Index.php:81
 Doctrine\DBAL\Schema\Index->_addColumn() at /www/vendor/doctrine/dbal/src/Schema/Index.php:72
 Doctrine\DBAL\Schema\Index->__construct() at /www/vendor/doctrine/dbal/src/Schema/AbstractSchemaManager.php:1500
 Doctrine\DBAL\Schema\AbstractSchemaManager->_getPortableTableIndexesList() at /www/vendor/doctrine/dbal/src/Schema/MySQLSchemaManager.php:153
 Doctrine\DBAL\Schema\MySQLSchemaManager->_getPortableTableIndexesList() at /www/vendor/doctrine/dbal/src/Schema/AbstractSchemaManager.php:424
 Doctrine\DBAL\Schema\AbstractSchemaManager->doListTables() at /www/vendor/doctrine/dbal/src/Schema/MySQLSchemaManager.php:66
 Doctrine\DBAL\Schema\MySQLSchemaManager->listTables() at /www/vendor/doctrine/dbal/src/Schema/AbstractSchemaManager.php:1651
 Doctrine\DBAL\Schema\AbstractSchemaManager->createSchema() at /www/vendor/doctrine/dbal/src/Schema/AbstractSchemaManager.php:1663
 Doctrine\DBAL\Schema\AbstractSchemaManager->introspectSchema() at /www/vendor/doctrine/migrations/src/Generator/DiffGenerator.php:117
 Doctrine\Migrations\Generator\DiffGenerator->createFromSchema() at /www/vendor/doctrine/migrations/src/Generator/DiffGenerator.php:63
 Doctrine\Migrations\Generator\DiffGenerator->generate() at /www/vendor/doctrine/migrations/src/Tools/Console/Command/DiffCommand.php:135
 Doctrine\Migrations\Tools\Console\Command\DiffCommand->execute() at /www/vendor/symfony/console/Command/Command.php:279
 Symfony\Component\Console\Command\Command->run() at /www/vendor/symfony/console/Application.php:1047
 Symfony\Component\Console\Application->doRunCommand() at /www/vendor/symfony/framework-bundle/Console/Application.php:123
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /www/vendor/symfony/console/Application.php:316
 Symfony\Component\Console\Application->doRun() at /www/vendor/symfony/framework-bundle/Console/Application.php:77
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /www/vendor/symfony/console/Application.php:167
 Symfony\Component\Console\Application->run() at /www/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:49
 Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run() at /www/vendor/autoload_runtime.php:29

Expected behavior

I would expect the schema tool to ignore an index without column, as it was not defined by doctrine.

How to reproduce

Create the index from the description, then run the doctrine:migrations:diff command.

Workaround

I added a check in AbstractSchemaManager::_getPortableTableIndexesList right before creating the new $index instance: if (! $defaultPrevented && ! in_array(null, $data['columns'], true)) {. I am not sure if that is a reasonable fix or has other side effects. That change would hide the index from doctrine.

Of note: With postgres, I get no error and the index is not seen in the schema tool.

dbu avatar Feb 12 '25 15:02 dbu

PR #6153 would fix it, the PR seems complete, not sure why it was closed, cc @prohalexey

faizanakram99 avatar Jul 09 '25 07:07 faizanakram99

looks like it was closed due to inactivity by the bot.

dbu avatar Jul 10 '25 13:07 dbu

@faizanakram99 feel free to take over this PR and fix the tests

greg0ire avatar Jul 10 '25 13:07 greg0ire