Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid creating unmanaged proxy instances for referred-to entities during merge() #10791

Merged
merged 2 commits into from
Jun 25, 2023

Commits on Jun 23, 2023

  1. Avoid creating unmanaged proxy instances for referred-to entities dur…

    …ing merge()
    
    This PR tries to improve the situation/problem explained in doctrine#3037:
    
    Under certain conditions – there may be multiple and not all are known/well-understood – we may get inconsistencies between the `\Doctrine\ORM\UnitOfWork::$entityIdentifiers` and `\Doctrine\ORM\UnitOfWork::$identityMap` arrays.
    
    Since the `::$identityMap` is a plain array holding object references, objects contained in it cannot be garbage-collected.
    `::$entityIdentifiers`, however, is indexed by `spl_object_id` values. When those objects are destructed and/or garbage-collected, the OID may be reused and reassigned to other objects later on.
    
    When the OID re-assignment happens to be for another entity, the UoW may assume incorrect entity states and, for example, miss INSERT or UPDATE operations.
    
    One cause for such inconsistencies is _replacing_ identity map entries with other object instances: This makes it possible that the old object becomes GC'd, while its OID is not cleaned up. Since that is not a use case we need to support (IMHO), doctrine#10785 is about adding a safeguard against it.
    
    In this test shown here, the `merge()` operation is currently too eager in creating a proxy object for another referred-to entity. This proxy represents an entity already present in the identity map at that time, potentially leading to this problem later on.
    mpdude committed Jun 23, 2023
    Configuration menu
    Copy the full SHA
    d738ecf View commit details
    Browse the repository at this point in the history
  2. Update tests/Doctrine/Tests/ORM/Functional/Ticket/GH7407Test.php

    Co-authored-by: Grégoire Paris <postmaster@greg0ire.fr>
    mpdude and greg0ire authored Jun 23, 2023
    Configuration menu
    Copy the full SHA
    1989531 View commit details
    Browse the repository at this point in the history