Skip to content

Loading…

DDC-2432: Entity can be initialized even if not found #3147

Closed
doctrinebot opened this Issue · 6 comments

2 participants

@doctrinebot

Jira issue originally created by user croensch:

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?

@doctrinebot

Comment created by @ocramius:

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

@doctrinebot

Comment created by croensch:

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?

@doctrinebot

Comment created by @ocramius:

[~croensch] 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

@doctrinebot

Comment created by croensch:

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](http://www.doctrine-project.org/jira/browse/DDC-2432)

@doctrinebot

Comment created by @ocramius:

Proposed a fix at #663

@doctrinebot

Issue was closed with resolution "Fixed"

@Ocramius Ocramius was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.4 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.