Uploaded image for project: 'Doctrine DBAL'
  1. Doctrine DBAL
  2. DBAL-232

Custom commented column type removal causes unknown column type exception

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 2.2.1
    • Fix Version/s: None
    • Component/s: Schema Managers
    • Security Level: All
    • Labels:
      None

      Description

      Problem happens when initially, as example, there was commented type "foo" registered and used:

      Doctrine\DBAL\Types\Type::addType('foo', 'FooType');
      $em->getConnection()
          ->getDatabasePlatform()
          ->markDoctrineTypeCommented(Doctrine\DBAL\Types\Type::getType('foo'));
      

      When the type usage and declaration is removed, the database schema upgrade fails.
      This is because DBAL reads the comment from the database and tries to find the type 'foo'.

      I suggest ignoring the database column comment and stick to the standard type recognition in case the type is not declared.

        Activity

        Hide
        gedrox Aigars Gedroics added a comment -

        Trivial solution would be:

        --- a/Doctrine/DBAL/Schema/AbstractSchemaManager.php
        +++ b/Doctrine/DBAL/Schema/AbstractSchemaManager.php
        @@ -878,7 +878,9 @@ abstract class AbstractSchemaManager
             public function extractDoctrineTypeFromComment($comment, $currentType)
             {
                 if (preg_match("(\(DC2Type:([a-zA-Z0-9]+)\))", $comment, $match)) {
        -            $currentType = $match[1];
        +                       if (Types\Type::hasType($match[1])) {
        +                               $currentType = $match[1];
        +                       }
                 }
                 return $currentType;
             }
        
        Show
        gedrox Aigars Gedroics added a comment - Trivial solution would be: --- a/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -878,7 +878,9 @@ abstract class AbstractSchemaManager public function extractDoctrineTypeFromComment($comment, $currentType) { if (preg_match( "(\(DC2Type:([a-zA-Z0-9]+)\))" , $comment, $match)) { - $currentType = $match[1]; + if (Types\Type::hasType($match[1])) { + $currentType = $match[1]; + } } return $currentType; }
        Hide
        deeky666 Steve Müller added a comment -

        Proposed solution applied in PR:

        https://github.com/doctrine/dbal/pull/406

        Show
        deeky666 Steve Müller added a comment - Proposed solution applied in PR: https://github.com/doctrine/dbal/pull/406
        Hide
        doctrinebot Doctrine Bot added a comment -

        A related Github Pull-Request [GH-406] was closed:
        https://github.com/doctrine/dbal/pull/406

        Show
        doctrinebot Doctrine Bot added a comment - A related Github Pull-Request [GH-406] was closed: https://github.com/doctrine/dbal/pull/406
        Hide
        deeky666 Steve Müller added a comment -

        As discussed with ocramius, it is not a good solution to silence this error during schema introspection. The problem has to be fixed by registering the missing types in the application or modifying the database schema manually by removing the column comment. This is what the current exception message suggest anyways.

        Show
        deeky666 Steve Müller added a comment - As discussed with ocramius, it is not a good solution to silence this error during schema introspection. The problem has to be fixed by registering the missing types in the application or modifying the database schema manually by removing the column comment. This is what the current exception message suggest anyways.

          People

          • Assignee:
            beberlei Benjamin Eberlei
            Reporter:
            gedrox Aigars Gedroics
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: