Skip to content

Regression in PR #2930 (Detach soft-deleted object from ObjectManager) #2963

@kopfsalat

Description

@kopfsalat

Environment

Package

show

$ composer show --latest gedmo/doctrine-extensions
name     : gedmo/doctrine-extensions
descrip. : Doctrine behavioral extensions
keywords : Blameable, behaviors, doctrine, extensions, gedmo, loggable, nestedset, odm, orm, sluggable, sortable, timestampable, translatable, tree, uploadable
versions : * v3.20.0
released : 2025-04-04, 2 months ago
latest   : v3.20.0 released 2025-04-04, 2 months ago
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : http://gediminasm.org/
source   : [git] https://github.com/doctrine-extensions/DoctrineExtensions.git ea1d37586b8e4bae2a815feb38b177894b12c44c
dist     : [zip] https://api.github.com/repos/doctrine-extensions/DoctrineExtensions/zipball/ea1d37586b8e4bae2a815feb38b177894b12c44c ea1d37586b8e4bae2a815feb38b177894b12c44c
path     : /home/jeldrik/projects/seedM/vendor/gedmo/doctrine-extensions
names    : gedmo/doctrine-extensions

Doctrine packages

show

$ composer show --latest 'doctrine/*'
Direct dependencies required in composer.json:
doctrine/annotations                1.14.4 2.0.2  Docblock Annotations Parser
doctrine/doctrine-bundle            2.14.0 2.15.0 Symfony DoctrineBundle
doctrine/doctrine-migrations-bundle 3.4.2  3.4.2  Symfony DoctrineMigrationsBundle
doctrine/orm                        2.20.3 3.4.1  Object-Relational-Mapper for PHP

Transitive dependencies not required in composer.json:
doctrine/cache                      2.2.0  2.2.0  PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb ...
doctrine/collections                2.3.0  2.3.0  PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/common                     3.5.0  3.5.0  PHP Doctrine Common project is a library that provides additional functionality that other Doctrine projects depend on such as better re...
doctrine/dbal                       3.9.4  4.2.4  Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
doctrine/deprecations               1.1.5  1.1.5  A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for pa...
doctrine/event-manager              2.0.1  2.0.1  The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.
doctrine/inflector                  2.0.10 2.0.10 PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms...
doctrine/instantiator               2.0.0  2.0.0  A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                      2.1.1  3.0.1  PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                 3.9.0  3.9.0  PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your datab...
doctrine/persistence                3.4.0  4.0.0  The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine object mappers share.
doctrine/sql-formatter              1.5.2  1.5.2  a PHP SQL highlighting library

PHP version

$ php -v
PHP 8.4.5 (cli) (built: Mar 15 2025 02:16:02) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.5, Copyright (c) Zend Technologies

Subject

Since updating to version 3.20, we have seen errors regarding cascade operations. The flow in our application is as follows (maybe sub optimal but right now it is what it is):

  1. An entity that is soft-deletable gets removed.
    1.1. There is a cascade DELETE operation on a "child" entity, which is "hard"-deleted. This child entity has a cascade SET NULL.
  2. Flush() is called.
  3. Other logic is executed, and at some point, another flush() call is made.
  4. The second flush() fails because the child cannot perform the SET NULL operation on the deleted parent.

We now believe that this was introduced by PR #2930 and it happens because the cascade delete is not executed during the first flush due to the detachment from the object manager. The second flush fails because of the cascade SET NULL on an object that is no longer part of the object manager.

I can confirm that all application logic is working as intended again after implementing the CompilerPass mentioned here: @rotdrop in #2930 (comment)

Expected results

No errors as in the previous version

Actual results

An Error Occurred! Uncaught PHP Exception Doctrine\ORM\ORMInvalidArgumentException: "A new entity was found through the relationship 'App\Entity\Bulk\JobTransfer#sourceBox' that was not configured to cascade persist operations for entity: XXX . To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example #[ORM\ManyToOne(..., cascade: ['persist'])]." at ORMInvalidArgumentException.php line 103

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA confirmed bug in Extensions that needs fixing.SoftDeleteable

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions