Skip to content
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

UniqueIndex attribute on entity can cause some packaged CLI tools to error #11246

Open
Firehed opened this issue Feb 11, 2024 · 1 comment
Open

Comments

@Firehed
Copy link

Firehed commented Feb 11, 2024

Bug Report

Q A
BC Break no
Version 3.0.0

Summary

If a table has a UniqueConstraint attribute where there's no name neing explicitly set (e.g. #[Mapping\UniqueConstraint(fields: ['email'])]), several included CLI tools produce an error:

TypeError: Doctrine\DBAL\Schema\Index::__construct(): Argument #1 ($name) must be of type ?string, int given, called in /app/vendor/doctrine/orm/src/Tools/SchemaTool.php on line 341 and defined in /app/vendor/doctrine/dbal/src/Schema/Index.php:42
Stack trace:
#0 /app/vendor/doctrine/orm/src/Tools/SchemaTool.php(341): Doctrine\DBAL\Schema\Index->__construct(0, Array, true, false, Array, Array)
#1 /app/vendor/doctrine/orm/src/Tools/SchemaTool.php(896): Doctrine\ORM\Tools\SchemaTool->getSchemaFromMetadata(Array)
#2 /app/vendor/doctrine/orm/src/Tools/Console/Command/SchemaTool/UpdateCommand.php(78): Doctrine\ORM\Tools\SchemaTool->getUpdateSchemaSql(Array)
#3 /app/vendor/doctrine/orm/src/Tools/Console/Command/SchemaTool/AbstractCommand.php(37): Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand->executeSchemaCommand(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput), Object(Doctrine\ORM\Tools\SchemaTool), Array, Object(Symfony\Component\Console\Style\SymfonyStyle))
#4 /app/vendor/symfony/console/Command/Command.php(279): Doctrine\ORM\Tools\Console\Command\SchemaTool\AbstractCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 /app/vendor/symfony/console/Application.php(1031): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 /app/vendor/symfony/console/Application.php(318): Symfony\Component\Console\Application->doRunCommand(Object(Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 /app/vendor/symfony/console/Application.php(169): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 /app/vendor/doctrine/orm/src/Tools/Console/ConsoleRunner.php(30): Symfony\Component\Console\Application->run()
#9 /app/cli(24): Doctrine\ORM\Tools\Console\ConsoleRunner::run(Object(Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider), Array)
#10 {main}

I also tested by replacing the UniqueConstraint with an Index and that has the correct behavior. It appears isolated to unique indexes.

Current behavior

Instead of a deterministic index name being generated from the referenced values, the above error is produced.

How to reproduce

  1. Define an entity with a UniqueConstraint attribute. Both fields and columns definitions reproduce this. Do not explicitly set a name.
  2. Configure Doctrine otherwise per normal.
  3. Run one of the following packaged CLI commands:
  • orm:info
  • orm:validate
  • orm:schema-tool:update --dump-sql

Expected behavior

If name is specified in the attribute, it's used (this IS the current behavior). If not, one is generated based on the columns as occurred in ORM 2.x.

@BenMorel
Copy link
Contributor

We have the same issue, and indeed, adding a name to each UniqueConstraint fixes it.
We're using version 3.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants