Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Won't Fix
-
Affects Version/s: 2.1.2
-
Fix Version/s: None
-
Component/s: Documentation, ORM
-
Security Level: All
-
Labels:None
Description
Hello,
I'm trying to get some clarification on http://www.doctrine-project.org/jira/browse/DDC-136 .
If I create an object in a limited scope and then persist+flush that object it should get saved into the storage engine. If the code execution leaves that scope the object gets destroyed by PHP garbage collection. Consequently, another new object can share the same spl_object_hash, if that new object is persisted+flushed then this can cause issues with Doctrine, assuming that the same instance of Doctrine is available in both scopes (in this case, via Symfony2 service container).
It would seem that this is caused because $this->documentStates in UnitOfWork.php does not (and could not) get updated when the first object is destroyed by garbage collection. That array maintains the object state of the previous object that shared the same hash, thus the wrong queries get executed against the storage engine when a second object with the same hash is processed.
Are you saying that this is the correct behavior?
DDC-136 suggests that detach() should be called for each object just before it goes out of scope, this does seem to fix the issue. However, it doesn't seem to be documented. I don't see how a user could otherwise be expected to know about this behavior, the description at http://doctrine-orm.readthedocs.org/en/2.0.x/reference/working-with-objects.html#detaching-entities gives no explanation of why detach() should be called, merely the effects of doing so which do not make it clear that it is ever necessary.
Personally I feel that spl_object_hash() is an inappropriate mechanism to use for this, however in the absence of any better suggestion it would be nice if the documentation reflected some of the quirks that should be expected.
Kind regards,
Tim.
Activity
| Field | Original Value | New Value |
|---|---|---|
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Resolution | Won't Fix [ 2 ] |
| Workflow | jira [ 13805 ] | jira-feedback [ 15397 ] |
| Workflow | jira-feedback [ 15397 ] | jira-feedback2 [ 17261 ] |
| Workflow | jira-feedback2 [ 17261 ] | jira-feedback3 [ 19517 ] |
- 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-1896, expand=changesets[-21:-1].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)
persist() + flush() does not leave the object out of scope. Its managed afterwards and saved inside the UnitOfWork. Only if you detach() the object it can be garbage collected, and consequently this method makes sure to cleanup all the spl_object_hash referenecs.
The probem with SplObjectStorage is, that the amout of calls to $storage[$object]['metadata'] is much slower than reusing a once computed hash.