doctrine-extensions / DoctrineExtensions

Doctrine2 behavioral extensions, Translatable, Sluggable, Tree-NestedSet, Timestampable, Loggable, Sortable
MIT License
4.01k stars 1.26k forks source link

Tree object class must have tree metadata at this point #2840

Open bettinz opened 2 weeks ago

bettinz commented 2 weeks ago

Environment

php 8.3, doctrine 3.2, Symfony 7.1

Package

show

``` 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.16.1 released : 2024-06-25, last week latest : v3.16.1 released 2024-06-25, last week 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 e85560ed96f977b8c29428a99222cb2ef2f0e80d dist : [zip] https://api.github.com/repos/doctrine-extensions/DoctrineExtensions/zipball/e85560ed96f977b8c29428a99222cb2ef2f0e80d e85560ed96f977b8c29428a99222cb2ef2f0e80d path : /Users/bettinz/PhpstormProjects/nutrione/vendor/gedmo/doctrine-extensions names : gedmo/doctrine-extensions support email : gediminas.morkevicius@gmail.com issues : https://github.com/doctrine-extensions/DoctrineExtensions/issues source : https://github.com/doctrine-extensions/DoctrineExtensions/tree/v3.16.1 wiki : https://github.com/Atlantic18/DoctrineExtensions/tree/main/doc autoload psr-4 Gedmo\ => src/ requires behat/transliterator ^1.2 doctrine/collections ^1.2 || ^2.0 doctrine/common ^2.13 || ^3.0 doctrine/deprecations ^1.0 doctrine/event-manager ^1.2 || ^2.0 doctrine/persistence ^2.2 || ^3.0 php ^7.4 || ^8.0 psr/cache ^1 || ^2 || ^3 psr/clock ^1 symfony/cache ^5.4 || ^6.0 || ^7.0 requires (dev) doctrine/annotations ^1.13 || ^2.0 doctrine/cache ^1.11 || ^2.0 doctrine/dbal ^3.2 doctrine/doctrine-bundle ^2.3 doctrine/mongodb-odm ^2.3 doctrine/orm ^2.14.0 || ^3.0 friendsofphp/php-cs-fixer ^3.14.0 nesbot/carbon ^2.71 || ^3.0 phpstan/phpstan ^1.11 phpstan/phpstan-doctrine ^1.4 phpstan/phpstan-phpunit ^1.4 phpunit/phpunit ^9.6 rector/rector ^1.1 symfony/console ^5.4 || ^6.0 || ^7.0 symfony/doctrine-bridge ^5.4 || ^6.0 || ^7.0 symfony/phpunit-bridge ^6.0 || ^7.0 symfony/uid ^5.4 || ^6.0 || ^7.0 symfony/yaml ^5.4 || ^6.0 || ^7.0 suggests doctrine/mongodb-odm to use the extensions with the MongoDB ODM doctrine/orm to use the extensions with the ORM conflicts doctrine/annotations <1.13 || >=3.0 doctrine/dbal <3.2 || >=4.0 doctrine/mongodb-odm <2.3 || >=3.0 doctrine/orm <2.14.0 || 2.16.0 || 2.16.1 || >=4.0 ```

Doctrine packages

show

``` Direct dependencies required in composer.json: doctrine/annotations 2.0.1 2.0.1 Docblock Annotations Parser doctrine/doctrine-bundle 2.12.0 2.12.0 Symfony DoctrineBundle doctrine/doctrine-migrations-bundle 3.3.1 3.3.1 Symfony DoctrineMigrationsBundle doctrine/orm 3.2.1 3.2.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 and others. doctrine/collections 2.2.2 2.2.2 PHP Doctrine Collections library that adds additional functionality on top of PHP arrays. doctrine/common 3.4.4 3.4.4 PHP Doctrine Common project is a library that provides additional functionality that other Doctrine projects depend on such as better reflection support, pro... doctrine/dbal 3.8.6 4.0.4 Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management. doctrine/deprecations 1.1.3 1.1.3 A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages. 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 of words. doctrine/instantiator 2.0.0 2.0.0 A small, lightweight utility to instantiate objects in PHP without invoking their constructors doctrine/lexer 3.0.1 3.0.1 PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers. doctrine/migrations 3.8.0 3.8.0 PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily... doctrine/persistence 3.3.3 3.3.3 The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine object mappers share. doctrine/sql-formatter 1.4.0 1.4.0 a PHP SQL highlighting library ```

PHP version

PHP 8.3.8 (cli) (built: Jun  4 2024 14:53:17) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.8, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.8, Copyright (c), by Zend Technologies

Subject

When upgrading to Doctrine 3, Symfony return this error: Tree object class: App\Entity\ must have tree metadata at this point

Minimal repository with the bug

Steps to reproduce

$this->em->getConfiguration()->addCustomHydrationMode('tree', \Gedmo\Tree\Hydrator\ORM\TreeObjectHydrator::class);       
 $repo = $this->em->getRepository(\App\Entity\<nameOfEntity>::class);       

Expected results

The result of the query (it works with doctrine v2)

Actual results

Exception: Tree object class: App\Entity\ must have tree metadata at this point

mbabker commented 2 weeks ago

You have the tree listener enabled, correct?

What type of mapping are you using for your entity? ORM 3.x doesn't support annotations, so if you've been using those, then you'll need to update to use attributes.

Your output shows that doctrine/annotations is installed. This library will default to using annotations for its internal metadata reader when that package is installed for B/C reasons unless you provide a reader service to the listeners, otherwise it will try defaulting to the attribute reader. If you're using StofDoctrineExtensionsBundle, the 1.12 release adds support for automatically using the attribute reader when needed; if you aren't using it, https://github.com/doctrine-extensions/DoctrineExtensions/blob/main/doc/symfony.md#doctrine-extension-listener-services can give you an idea on how to configure your services to provide the attribute reader.