Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2317

[UnitOfWork] Entity in identityMap but not present in entityIdentifiers

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 2.3.2
    • Fix Version/s: None
    • Component/s: ORM
    • Labels:
    • Environment:
      php 5.4.11, MySQL 5.5, ubuntu 12.10

      Description

      I'm using symfony 2.1.8 and sonata/admin-bundle
      I have a quite complex entity mapping.

      • A Competence has many CompetenceAction (superclass)
      • CompetenceActionBuff is a subclass of CompetenceAction and has exactly one buff (selectable in the form by an 'entity' field).

      When i want to edit a Competence, i have the following error message about the Buff entity linked to the CompetenceActionBuff:
      "Entities passed to the choice field must be managed. [...]"
      The exception is raised in Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php at line 412

      I've added some debug code in the EntityManager::contains() method and it shows that my entity is in the entityMap but his oid is not in the keys of entityIdentifiers making the call to UnitOfWork::isInIdentityMap() return false at line 1505.

      When submitting the form, there is no problems. All the entities are correctly created in the database. The exception is thrown only when i want to edit the Competence object. Saying that the Buff object is not managed when it was first loaded from the database... strange, no?

      Finally, i tried to comment the test

      if (!$this->em->contains($entity)))

      in EntityChoiceList::getIdentifierValues() and everything seemed to work properly.

      1. Buff.php
        4 kB
        Rémi Piotaix
      2. Competence.php
        10 kB
        Rémi Piotaix
      3. CompetenceAction.php
        4 kB
        Rémi Piotaix
      4. CompetenceActionBuff.php
        1.0 kB
        Rémi Piotaix
      5. CompetenceActionBuffType.php
        1 kB
        Rémi Piotaix

        Activity

        Rémi Piotaix created issue -
        Rémi Piotaix made changes -
        Field Original Value New Value
        Description First, i'd like to say that i'm a beginner with doctrine, jira and all this stuff and i apologize if i'm doing something wrong. I'm also sorry for my bad english. I'm french and it is really difficult for me :s

        I'm using symfony 2.1.8 and sonata/admin-bundle
        I have a quite complex entity mapping.

        Here is my problem (i've put the entities as attachments):

        - A Competence has many CompetenceAction (superclass)
        - CompetenceActionBuff is a subclass of CompetenceAction and has exactly one buff (selectable in the form by an 'entity' field).

        When i want to create/edit a Competence, i have the following error message about the Buff entity linked to the CompetenceActionBuff:
        "Entities passed to the choice field must be managed. [...]"
        The exception is raised in Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php at line 412

        I've added some debug code in the EntityManager::contains() method and it shows that my entity is in the entityMap but his oid is not in the keys of entityIdentifiers making the call to UnitOfWork::isInIdentityMap() return false at line 1505.

        When submitting the form, there is no problems. All the entities are correctly created in the database. The exception is thrown only when i want to edit the Competence object. Saying that the Buff object is not managed when it was first loaded from the database... strange, no?

        Finally, i tried to comment the test (if (!$this->em->contains($entity))) in EntityChoiceList::getIdentifierValues() and everything seemed to work properly.
        First, i'd like to say that i'm a beginner with doctrine, jira and all this stuff and i apologize if i'm doing something wrong. I'm also sorry for my bad english. I'm french and it is really difficult for me :s

        I'm using symfony 2.1.8 and sonata/admin-bundle
        I have a quite complex entity mapping.

        Here is my problem (i've put the entities as attachments):

        - A Competence has many CompetenceAction (superclass)
        - CompetenceActionBuff is a subclass of CompetenceAction and has exactly one buff (selectable in the form by an 'entity' field).

        When i want to edit a Competence, i have the following error message about the Buff entity linked to the CompetenceActionBuff:
        "Entities passed to the choice field must be managed. [...]"
        The exception is raised in Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php at line 412

        I've added some debug code in the EntityManager::contains() method and it shows that my entity is in the entityMap but his oid is not in the keys of entityIdentifiers making the call to UnitOfWork::isInIdentityMap() return false at line 1505.

        When submitting the form, there is no problems. All the entities are correctly created in the database. The exception is thrown only when i want to edit the Competence object. Saying that the Buff object is not managed when it was first loaded from the database... strange, no?

        Finally, i tried to comment the test (if (!$this->em->contains($entity))) in EntityChoiceList::getIdentifierValues() and everything seemed to work properly.
        Hide
        Marco Pivetta added a comment -

        Can you please reproduce this in an insulated environment (without symfony forms involved)?

        Show
        Marco Pivetta added a comment - Can you please reproduce this in an insulated environment (without symfony forms involved)?
        Marco Pivetta made changes -
        Priority Blocker [ 1 ] Major [ 3 ]
        Description First, i'd like to say that i'm a beginner with doctrine, jira and all this stuff and i apologize if i'm doing something wrong. I'm also sorry for my bad english. I'm french and it is really difficult for me :s

        I'm using symfony 2.1.8 and sonata/admin-bundle
        I have a quite complex entity mapping.

        Here is my problem (i've put the entities as attachments):

        - A Competence has many CompetenceAction (superclass)
        - CompetenceActionBuff is a subclass of CompetenceAction and has exactly one buff (selectable in the form by an 'entity' field).

        When i want to edit a Competence, i have the following error message about the Buff entity linked to the CompetenceActionBuff:
        "Entities passed to the choice field must be managed. [...]"
        The exception is raised in Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php at line 412

        I've added some debug code in the EntityManager::contains() method and it shows that my entity is in the entityMap but his oid is not in the keys of entityIdentifiers making the call to UnitOfWork::isInIdentityMap() return false at line 1505.

        When submitting the form, there is no problems. All the entities are correctly created in the database. The exception is thrown only when i want to edit the Competence object. Saying that the Buff object is not managed when it was first loaded from the database... strange, no?

        Finally, i tried to comment the test (if (!$this->em->contains($entity))) in EntityChoiceList::getIdentifierValues() and everything seemed to work properly.
        I'm using symfony 2.1.8 and sonata/admin-bundle
        I have a quite complex entity mapping.

         - A Competence has many CompetenceAction (superclass)
         - CompetenceActionBuff is a subclass of CompetenceAction and has exactly one buff (selectable in the form by an 'entity' field).

        When i want to edit a Competence, i have the following error message about the Buff entity linked to the CompetenceActionBuff:
        "Entities passed to the choice field must be managed. [...]"
        The exception is raised in Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php at line 412

        I've added some debug code in the EntityManager::contains() method and it shows that my entity is in the entityMap but his oid is not in the keys of entityIdentifiers making the call to UnitOfWork::isInIdentityMap() return false at line 1505.

        When submitting the form, there is no problems. All the entities are correctly created in the database. The exception is thrown only when i want to edit the Competence object. Saying that the Buff object is not managed when it was first loaded from the database... strange, no?

        Finally, i tried to comment the test
        {code}if (!$this->em->contains($entity))){code} in EntityChoiceList::getIdentifierValues() and everything seemed to work properly.
        Hide
        Rémi Piotaix added a comment -

        By doing this, all work properly, the exception is not thrown:

        $competence = $this->getRepo(\Sistearth\JeuBundle\Entity\Competence\Competence::REPO)->find(1);
        $buff = $competence->getActions()[0]->getBuff();
              
        $em = $this->getDoctrine()->getEntityManager();
                
        if(!$em->contains($buff))
            throw new \Exception("Not in EntityManager");
        

        but if i add this after:

        $form = $this->createForm(new \Sistearth\JeuBundle\Form\Competence\CompetenceType(), $competence);
        

        then, the exception "Entities passed to the choice field must be managed. Maybe persist them in the entity manager?" is back.

        I'll try to do some others tests...

        Show
        Rémi Piotaix added a comment - By doing this, all work properly, the exception is not thrown: $competence = $ this ->getRepo(\Sistearth\JeuBundle\Entity\Competence\Competence::REPO)->find(1); $buff = $competence->getActions()[0]->getBuff(); $em = $ this ->getDoctrine()->getEntityManager(); if (!$em->contains($buff)) throw new \Exception( "Not in EntityManager" ); but if i add this after: $form = $ this ->createForm( new \Sistearth\JeuBundle\Form\Competence\CompetenceType(), $competence); then, the exception "Entities passed to the choice field must be managed. Maybe persist them in the entity manager?" is back. I'll try to do some others tests...
        Hide
        Marco Pivetta added a comment - - edited

        Rémi Piotaix the problem is exactly the last bit Doctrine has no forms, so you will have to create a small script that reproduces the problem without symfony, starting from:

        php composer.phar require doctrine/orm:dev-master@dev
        Show
        Marco Pivetta added a comment - - edited Rémi Piotaix the problem is exactly the last bit Doctrine has no forms, so you will have to create a small script that reproduces the problem without symfony, starting from: php composer.phar require doctrine/orm:dev-master@dev
        Hide
        Rémi Piotaix added a comment -

        Bug found!

        In the form type CompetenceActionBuffType, i marked the field buff with

        array('by_reference"=>false)

        . If by_reference is set to false, the modelData is cloned (here the Buff proxy) at line 349 in Form.php.
        And, by cloning the object, the spl_object_hash of the clone is different from the original one's.

        Is this a symfony Form component bug or a doctrine one?

        Show
        Rémi Piotaix added a comment - Bug found! In the form type CompetenceActionBuffType, i marked the field buff with array('by_reference"=> false ) . If by_reference is set to false, the modelData is cloned (here the Buff proxy) at line 349 in Form.php. And, by cloning the object, the spl_object_hash of the clone is different from the original one's. Is this a symfony Form component bug or a doctrine one?
        Rémi Piotaix made changes -
        Attachment CompetenceActionBuffType.php [ 11414 ]
        Hide
        Marco Pivetta added a comment -

        Rémi Piotaix this is a problem of symfony forms, please report it on the symfony issue tracker (check if there's a similar open issue first) at https://github.com/symfony/symfony/issues/

        Show
        Marco Pivetta added a comment - Rémi Piotaix this is a problem of symfony forms, please report it on the symfony issue tracker (check if there's a similar open issue first) at https://github.com/symfony/symfony/issues/
        Marco Pivetta made changes -
        Status Open [ 1 ] Closed [ 6 ]
        Assignee Benjamin Eberlei [ beberlei ] Marco Pivetta [ ocramius ]
        Resolution Invalid [ 6 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-2317, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            Rémi Piotaix
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: