Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-3125

Better Exception Descriptions / Undefined index Handling

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Trivial Trivial
    • Resolution: Can't Fix
    • Affects Version/s: 2.4
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:
      None
    • Environment:
      PHP 5.3.10-1, Zend Engine v2.3.0, Xdebug v2.2.2, Composer

      Description

      Some warnings are not very helpful for beginners if the presented text does not state what the Code is trying to accomplish.

      Example:

      Notice: Undefined index: test in /vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php on line 1753

      And followed by another warning:

      Warning: Invalid argument supplied for foreach() in vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php on line 1758

      Another example:

      Notice: Undefined index: unknownField in vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 2611

      -> Resulted from a wrong defition:

      @ORM\JoinColumn(referencedColumnName="unknownField")

      Possible Fix:

      Doctrine\ORM\Persisters\BasicEntityParser::getOneToManyStatement
      private function getOneToManyStatement(array $assoc, $sourceEntity, $offset = null, $limit = null)
          {
              $criteria = array();
              if ( ! isset($this->class->associationMappings[$assoc['mappedBy']])) {
                throw new MappingException(
                  "No associations/mappings defined for " . $assoc['mappedBy'].
                  ". Available: " . implode(', ', array_keys($this->class->associationMappings))
                );
              }
      ...
      

        Activity

        Hide
        Steve Müller added a comment -

        TBH I'm with Marco Pivetta opinion. UoW is a very performance sensitive component and we should not try to catch every edge case just because of invalid usage. Maybe we just need to improve the documentation on this (for your use cases).

        Show
        Steve Müller added a comment - TBH I'm with Marco Pivetta opinion. UoW is a very performance sensitive component and we should not try to catch every edge case just because of invalid usage. Maybe we just need to improve the documentation on this (for your use cases).
        Hide
        Marco Pivetta added a comment -

        Not sure where it is documented (can't find it atm), but I thought it is clear that the UoW works under the assumption that there is only one object per identifier per type in the UoW at any time.

        Show
        Marco Pivetta added a comment - Not sure where it is documented (can't find it atm), but I thought it is clear that the UoW works under the assumption that there is only one object per identifier per type in the UoW at any time.
        Hide
        René Patzer added a comment - - edited

        Found another one when writing Repository-Classes:

        PHP Notice: Undefined index: publisher in [...]/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php on line 415
        PHP Stack trace:
        {...]
        PHP 4. Doctrine\ORM\AbstractQuery->execute() [...]/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:574
        PHP 5. Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll() [...]/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:804
        PHP 6. Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateAllData() [...]/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php:140
        PHP 7. Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateRowData() [...]/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:179

        Schema validation says (since the problem is in the Repository-class):

        [Mapping] OK - The mapping files are correct.

        I have a many-to-one and a one-to-many relation like in this example:
        http://codemonkeys.be/2013/02/example-of-a-doctrine-2-x-many-to-many-association-class/

        Thx in advance

        Show
        René Patzer added a comment - - edited Found another one when writing Repository-Classes: PHP Notice: Undefined index: publisher in [...] /vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php on line 415 PHP Stack trace: {...] PHP 4. Doctrine\ORM\AbstractQuery->execute() [...] /vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:574 PHP 5. Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll() [...] /vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php:804 PHP 6. Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateAllData() [...] /vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php:140 PHP 7. Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateRowData() [...] /vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:179 Schema validation says (since the problem is in the Repository-class): [Mapping] OK - The mapping files are correct. I have a many-to-one and a one-to-many relation like in this example: http://codemonkeys.be/2013/02/example-of-a-doctrine-2-x-many-to-many-association-class/ Thx in advance
        Hide
        Marco Pivetta added a comment -

        René Patzer there is no publisher field in the linked example

        Show
        Marco Pivetta added a comment - René Patzer there is no publisher field in the linked example
        Hide
        René Patzer added a comment -

        Here is an example:
        http://pastebin.com/SN1s2xU8

        Testdata is in the class-comment, see the Repository-Class on how to provoke the warning ("Undefined index: id in DoctrineTest/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 2487").

        Just to make my point clear and point out why the warning is puzzling for beginners:
        I asked myself "why is there an index 'id' missing?" - after debugging around in the code to see what's what i remembered Doctrine is using "id" as the identifier as default if no other name is given (in this example: "p_publisher_id" was missing in the resultset) and it seems to miss a value.

        The warning should have contained why it was trying to access that "id"-field (e.g. "tried to get value p_publisher_id or id - neither was found - check your resultset").

        hth
        Kind regards

        Show
        René Patzer added a comment - Here is an example: http://pastebin.com/SN1s2xU8 Testdata is in the class-comment, see the Repository-Class on how to provoke the warning ("Undefined index: id in DoctrineTest/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 2487"). Just to make my point clear and point out why the warning is puzzling for beginners: I asked myself "why is there an index 'id' missing?" - after debugging around in the code to see what's what i remembered Doctrine is using "id" as the identifier as default if no other name is given (in this example: "p_publisher_id" was missing in the resultset) and it seems to miss a value. The warning should have contained why it was trying to access that "id"-field (e.g. "tried to get value p_publisher_id or id - neither was found - check your resultset"). hth Kind regards

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            René Patzer
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: