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

Closed
opened 2026-01-22 14:10:49 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (May 6, 2013).

Originally assigned to: @Ocramius on GitHub.

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?

Originally created by @doctrinebot on GitHub (May 6, 2013). Originally assigned to: @Ocramius on GitHub. 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?
admin added the Bug label 2026-01-22 14:10:49 +01:00
admin closed this issue 2026-01-22 14:10:49 +01:00
Author
Owner

@doctrinebot commented on GitHub (May 6, 2013):

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 commented on GitHub (May 6, 2013): Comment created by @ocramius: That is specifically there to disallow recursive load operations that may occur - did you already try this with latest master?
Author
Owner

@doctrinebot commented on GitHub (May 7, 2013):

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 commented on GitHub (May 7, 2013): 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?
Author
Owner

@doctrinebot commented on GitHub (May 7, 2013):

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 commented on GitHub (May 7, 2013): 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
Author
Owner

@doctrinebot commented on GitHub (May 8, 2013):

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

@doctrinebot commented on GitHub (May 8, 2013): 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)
Author
Owner

@doctrinebot commented on GitHub (May 9, 2013):

Comment created by @ocramius:

Proposed a fix at https://github.com/doctrine/doctrine2/pull/663

@doctrinebot commented on GitHub (May 9, 2013): Comment created by @ocramius: Proposed a fix at https://github.com/doctrine/doctrine2/pull/663
Author
Owner

@doctrinebot commented on GitHub (May 9, 2013):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (May 9, 2013): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3050