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

        Christoph Roensch created issue -
        Christoph Roensch made changes -
        Field Original Value New Value
        Affects Version/s 2.3.3 [ 10329 ]
        Affects Version/s 2.2 [ 10157 ]
        Marco Pivetta made changes -
        Assignee Benjamin Eberlei [ beberlei ] Marco Pivetta [ ocramius ]
        Benjamin Eberlei made changes -
        Priority Minor [ 4 ] Critical [ 2 ]
        Marco Pivetta made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Benjamin Eberlei made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Fix Version/s 2.4 [ 10321 ]
        Resolution Fixed [ 1 ]

          People

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

            Dates

            • Created:
              Updated:
              Resolved: