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

Fix SchemaTool::getSchemaFromMetadata() uniqueConstraint without a predefined name #11314

Merged

Conversation

rmotaln
Copy link
Contributor

@rmotaln rmotaln commented Feb 26, 2024

Bug Report

Q A
BC Break no
Version 3.0.x

Summary

SchemaTool can't correctly read a UniqueConstraint when it doesn't have a name specified.

Current behavior

If a unique constraint is specified for a table without a defined name i.e.: #[ORM\UniqueConstraint(fields: ['field', 'anotherField'])], the reading fails due to a type missmatch here. In such a case the $indexName is an integer but it should be null. This is correctly applied here

How to reproduce

Add a #[ORM\UniqueConstraint(fields: ['field', 'anotherField'])] to any entity and try to dump SQL. You will get

In Index.php line 42:
                                                                                                                                                                                          
  Doctrine\DBAL\Schema\Index::__construct(): Argument #1 ($name) must be of type ?string, int given, called in vendor/doctrine/orm/src/Tools/SchemaTool.php on line 340

Expected behavior

The unique constraint should be loaded correctly and a unique name should be generated for it automatically.

@rmotaln rmotaln force-pushed the fix-schema-tool-unique-constraint-read branch from a01a45e to 4e8174a Compare February 26, 2024 22:23
@rmotaln rmotaln marked this pull request as ready for review February 26, 2024 22:25
src/Tools/SchemaTool.php Outdated Show resolved Hide resolved
@derrabus derrabus force-pushed the fix-schema-tool-unique-constraint-read branch from 4e8174a to f18ac73 Compare March 3, 2024 14:13
@derrabus derrabus added the Bug label Mar 3, 2024
rmotaln and others added 2 commits March 3, 2024 15:24
…out a name

Fixes a type miss-match exception when reading a UniqueConstraint defined on an Entity which doesn't have a predefined name.
@derrabus derrabus force-pushed the fix-schema-tool-unique-constraint-read branch from f18ac73 to 706d7b6 Compare March 3, 2024 14:28
@derrabus derrabus changed the base branch from 3.0.x to 2.18.x March 3, 2024 14:28
@derrabus derrabus added this to the 2.18.3 milestone Mar 3, 2024
@derrabus derrabus closed this Mar 3, 2024
@derrabus derrabus reopened this Mar 3, 2024
@derrabus derrabus merged commit ab5e9e3 into doctrine:2.18.x Mar 3, 2024
68 of 83 checks passed
derrabus added a commit that referenced this pull request Mar 3, 2024
* 2.18.x:
  Bump CI workflows (#11336)
  Fix SchemaTool::getSchemaFromMetadata() uniqueConstraint without a predefined name (#11314)
derrabus added a commit to derrabus/orm that referenced this pull request Mar 3, 2024
* 2.18.x:
  Fix annotation
  Bump CI workflows (doctrine#11336)
  Fix SchemaTool::getSchemaFromMetadata() uniqueConstraint without a predefined name (doctrine#11314)
derrabus added a commit to derrabus/orm that referenced this pull request Mar 3, 2024
* 2.18.x:
  Fix annotation
  Bump CI workflows (doctrine#11336)
  Fix SchemaTool::getSchemaFromMetadata() uniqueConstraint without a predefined name (doctrine#11314)
derrabus added a commit to derrabus/orm that referenced this pull request Mar 3, 2024
* 2.18.x:
  Fix annotation
  Bump CI workflows (doctrine#11336)
  Fix SchemaTool::getSchemaFromMetadata() uniqueConstraint without a predefined name (doctrine#11314)
derrabus added a commit that referenced this pull request Mar 3, 2024
* 3.0.x:
  Fix annotation
  Bump CI workflows (#11336)
  Fix SchemaTool::getSchemaFromMetadata() uniqueConstraint without a predefined name (#11314)
derrabus added a commit that referenced this pull request Mar 3, 2024
* 3.1.x:
  Fix annotation
  Bump CI workflows (#11336)
  Fix SchemaTool::getSchemaFromMetadata() uniqueConstraint without a predefined name (#11314)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants