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

[tree] Inserts null ids into closure table when persisting more than one type of entity #2652

Closed
JDruery opened this issue Jul 23, 2023 · 1 comment · May be fixed by #2653
Closed

[tree] Inserts null ids into closure table when persisting more than one type of entity #2652

JDruery opened this issue Jul 23, 2023 · 1 comment · May be fixed by #2653
Labels
Bug A confirmed bug in Extensions that needs fixing. Stale Tree

Comments

@JDruery
Copy link

JDruery commented Jul 23, 2023

Environment

Package

show

$ composer show --latest gedmo/doctrine-extensions
Info from https://repo.packagist.org: #StandWithUkraine
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.11.1
latest   : v3.12.0
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 ae4bdf0d567e06b6bb1902a560ee78961b230953
dist     : [zip] https://api.github.com/repos/doctrine-extensions/DoctrineExtensions/zipball/ae4bdf0d567e06b6bb1902a560ee78961b230953 ae4bdf0d567e06b6bb1902a560ee78961b230953
path     : /srv/app/vendor/gedmo/doctrine-extensions
names    : gedmo/doctrine-extensions

support
email : [email protected]
issues : https://github.com/doctrine-extensions/DoctrineExtensions/issues
source : https://github.com/doctrine-extensions/DoctrineExtensions/tree/v3.11.1
wiki : https://github.com/Atlantic18/DoctrineExtensions/tree/main/doc

autoload
psr-4
Gedmo\ => src/

requires
behat/transliterator ~1.2
doctrine/annotations ^1.13 || ^2.0
doctrine/collections ^1.2 || ^2.0
doctrine/common ^2.13 || ^3.0
doctrine/event-manager ^1.2 || ^2.0
doctrine/persistence ^2.2 || ^3.0
php ^7.2 || ^8.0
psr/cache ^1 || ^2 || ^3
symfony/cache ^4.4 || ^5.3 || ^6.0
symfony/deprecation-contracts ^2.1 || ^3.0

requires (dev)
doctrine/cache ^1.11 || ^2.0
doctrine/dbal ^2.13.1 || ^3.2
doctrine/doctrine-bundle ^2.3
doctrine/mongodb-odm ^2.3
doctrine/orm ^2.10.2
friendsofphp/php-cs-fixer ^3.4.0,<3.10
nesbot/carbon ^2.55
phpstan/phpstan ^1.9
phpstan/phpstan-doctrine ^1.0
phpstan/phpstan-phpunit ^1.0
phpunit/phpunit ^8.5 || ^9.5
symfony/console ^4.4 || ^5.3 || ^6.0
symfony/phpunit-bridge ^6.0
symfony/yaml ^4.4 || ^5.3 || ^6.0

suggests
doctrine/mongodb-odm to use the extensions with the MongoDB ODM
doctrine/orm to use the extensions with the ORM
symfony/cache to cache parsed annotations

conflicts
doctrine/cache <1.11
doctrine/dbal <2.13.1 || ^3.0 <3.2
doctrine/mongodb-odm <2.3
doctrine/orm <2.10.2
sebastian/comparator <2.0

Doctrine packages

show

$ composer show --latest 'doctrine/*'
Direct dependencies required in composer.json:
doctrine/annotations                1.14.3 2.0.1  Docblock Annotations Parser
doctrine/doctrine-bundle            2.10.0 2.10.1 Symfony DoctrineBundle
doctrine/doctrine-migrations-bundle 3.2.4  3.2.4  Symfony DoctrineMigrationsBundle
doctrine/orm                        2.15.2 2.15.3 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 ...
doctrine/collections                2.1.2  2.1.2  PHP Doctrine Collections library that adds additional functionalit...
doctrine/common                     3.4.3  3.4.3  PHP Doctrine Common project is a library that provides additional ...
doctrine/data-fixtures              1.6.6  1.6.6  Data Fixtures for all Doctrine Object Managers
doctrine/dbal                       3.6.3  3.6.4  Powerful PHP database abstraction layer (DBAL) with many features ...
doctrine/deprecations               v1.1.1 v1.1.1 A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 ...
doctrine/event-manager              2.0.0  2.0.0  The Doctrine Event Manager is a simple PHP event system that was b...
doctrine/inflector                  2.0.6  2.0.8  PHP Doctrine Inflector is a small library that can perform string ...
doctrine/instantiator               2.0.0  2.0.0  A small, lightweight utility to instantiate objects in PHP without...
doctrine/lexer                      2.1.0  3.0.0  PHP Doctrine Lexer parser library that can be used in Top-Down, Re...
doctrine/migrations                 3.6.0  3.6.0  PHP Doctrine Migrations project offer additional functionality on ...
doctrine/persistence                3.2.0  3.2.0  The Doctrine Persistence project is a set of shared interfaces and...
doctrine/sql-formatter              1.1.3  1.1.3  a PHP SQL highlighting library

PHP version

$ php -v
PHP 8.2.8 (cli) (built: Jul 10 2023 22:24:17) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.8, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.8, Copyright (c), by Zend Technologies
    with Xdebug v3.2.2, Copyright (c) 2002-2023, by Derick Rethans

Subject

I'm trying to use the closure strategy on multiple entities, and Closure.php inserts closures before all the entities have been persisted, which results in an attempt to insert null values into the closure table's ancestor and descendant columns.

Steps to reproduce

  • Create two entities that use the closure tree strategy (entity1 and entity2)
  • Use hautelook/alice-bundle to insert fixtures. Add fixtures with one root node for each type of entity.
  • Load the fixtures.

Expected results

Two rows should be added to the closure table, one for each entity fixture, with the ancestor and descendant columns containing the id for each fixture.

Actual results

Both types of fixtures will be loaded. In Closure.php, processPrePersist will queue up the child node inserts (in pendingChildNodeInserts). When when the fixture for entity1 is persisted, the processPostPersist method of Closure.php will attempt to insert closures for both the entity1 and entity2 fixtures, but the entity2 fixture hasn't been persisted yet. It will loop through pendingChildNodeInserts, and when it gets to the fixture for entity2, the nodeId will be null.

The output is as follows:

In ExceptionConverter.php line 47:

  An exception occurred while executing a query: SQLSTATE[23502]: Not null violation: 7 ERROR:  null value in column
  "ancestor" of relation "gf_group_criteria_closure" violates not-null constraint
  DETAIL:  Failing row contains (1, null, null, 0).


In Exception.php line 28:

  SQLSTATE[23502]: Not null violation: 7 ERROR:  null value in column "ancestor" of relation "gf_group_criteria_closu
  re" violates not-null constraint
  DETAIL:  Failing row contains (1, null, null, 0).


In Statement.php line 121:

  SQLSTATE[23502]: Not null violation: 7 ERROR:  null value in column "ancestor" of relation "gf_group_criteria_closu
  re" violates not-null constraint
  DETAIL:  Failing row contains (1, null, null, 0).
JDruery added a commit to JDruery/DoctrineExtensions that referenced this issue Jul 24, 2023
@phansys phansys added Bug A confirmed bug in Extensions that needs fixing. Tree labels Jul 24, 2023
JDruery added a commit to JDruery/DoctrineExtensions that referenced this issue Sep 12, 2023
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Jan 21, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 20, 2024
JDruery added a commit to JDruery/DoctrineExtensions that referenced this issue Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A confirmed bug in Extensions that needs fixing. Stale Tree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants