Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2432

Entity can be initialized even if not found

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.3.3
    • Fix Version/s: 2.4
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      I have some data in loose consistency, trying to load a field from a certain entity will yield a EntityNotFoundException. Trying it again, for example if the group is reused in a set that gets iterated, will work but provide an empty/dirty Entity.

      try {
        echo $item->getGroup()->getName();
      } catch (\Doctrine\ORM\EntityNotFoundException $enfe) {
        // meh
      }
      

      Thats probably because the proxies internal methods set _isInitialized_ to true on the first try. Without reverting it in case of the exception...

          public function __load()
          {
              if (!$this->__isInitialized__ && $this->_entityPersister) {
                  $this->__isInitialized__ = true;
      
                  if ($this->_entityPersister->load($this->_identifier, $this) === null) {
                      throw new \Doctrine\ORM\EntityNotFoundException();
                  }
                  unset($this->_entityPersister, $this->_identifier);
              }
          }
      

      Is there any reason to do that?

        Activity

        Hide
        Marco Pivetta added a comment -

        That is specifically there to disallow recursive load operations that may occur - did you already try this with latest master?

        Show
        Marco Pivetta added a comment - That is specifically there to disallow recursive load operations that may occur - did you already try this with latest master?
        Hide
        Christoph Roensch added a comment -

        I did not exactly use an "Doctrine Proxy". A colleque of me implemented his own proxies, wich instead of loading from an entity manager, load stuff from a webservice. He simply used the template that a normal proxy provided and thats where i found this case, throw exception - return initialized. Wich i found would be valid for real proxies too.

        Now i tried to use http://www.doctrine-project.org/blog/doctrine-2-4-beta.html but the composer install just fails because common cant be resolved atm. So i downloaded and compiled all tarballs from github into our project. Now the proxy mechanism seems changed, with an _initializer_ closure instead. Our "Entities" in question won't work with that anymore...

        I would have to construct a demo then, implementing real basic proxies with a RDBMS?

        Show
        Christoph Roensch added a comment - I did not exactly use an "Doctrine Proxy". A colleque of me implemented his own proxies, wich instead of loading from an entity manager, load stuff from a webservice. He simply used the template that a normal proxy provided and thats where i found this case, throw exception - return initialized. Wich i found would be valid for real proxies too. Now i tried to use http://www.doctrine-project.org/blog/doctrine-2-4-beta.html but the composer install just fails because common cant be resolved atm. So i downloaded and compiled all tarballs from github into our project. Now the proxy mechanism seems changed, with an _ initializer _ closure instead. Our "Entities" in question won't work with that anymore... I would have to construct a demo then, implementing real basic proxies with a RDBMS?
        Hide
        Marco Pivetta added a comment - - edited

        Christoph Roensch did you try setting the minimum-stability flag in composer? Give it a try again with 2.4 and ping back - proxies changed a lot since 2.3

        Show
        Marco Pivetta added a comment - - edited Christoph Roensch did you try setting the minimum-stability flag in composer? Give it a try again with 2.4 and ping back - proxies changed a lot since 2.3
        Hide
        Christoph Roensch added a comment -

        I reproduced it with the tutorial application, please have a look at the two commits i made on https://github.com/croensch/doctrine2-orm-tutorial/tree/DDC-2432

        Show
        Christoph Roensch added a comment - I reproduced it with the tutorial application, please have a look at the two commits i made on https://github.com/croensch/doctrine2-orm-tutorial/tree/DDC-2432
        Hide
        Marco Pivetta added a comment -
        Show
        Marco Pivetta added a comment - Proposed a fix at https://github.com/doctrine/doctrine2/pull/663

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            Christoph Roensch
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: