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

ORM 3 deprecations #2827

Open
zorn-v opened this issue Jun 25, 2024 · 12 comments · May be fixed by #2889
Open

ORM 3 deprecations #2827

zorn-v opened this issue Jun 25, 2024 · 12 comments · May be fixed by #2889

Comments

@zorn-v
Copy link

zorn-v commented Jun 25, 2024

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.16.0
released : 2024-06-24, this week
latest   : v3.16.0 released 2024-06-24, this 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 7832a3059bdaf14433a2a2515d533c6a16e58520
dist     : [zip] https://api.github.com/repos/doctrine-extensions/DoctrineExtensions/zipball/7832a3059bdaf14433a2a2515d533c6a16e58520 7832a3059bdaf14433a2a2515d533c6a16e58520
path     : /mnt/M.2/Develop/mark/prokat/prokat/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.16.0
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

$ composer show --latest 'doctrine/*'

Direct dependencies required in composer.json:
doctrine/dbal                       3.8.6  4.0.4  Powerful PHP database abstraction layer...
doctrine/doctrine-bundle            2.12.0 2.12.0 Symfony DoctrineBundle
doctrine/doctrine-migrations-bundle 3.3.1  3.3.1  Symfony DoctrineMigrationsBundle

Transitive dependencies not required in composer.json:
doctrine/cache                      2.2.0  2.2.0  PHP Doctrine Cache library is a popular...
doctrine/collections                2.2.2  2.2.2  PHP Doctrine Collections library that a...
doctrine/common                     3.4.4  3.4.4  PHP Doctrine Common project is a librar...
doctrine/deprecations               1.1.3  1.1.3  A small layer on top of trigger_error(E...
doctrine/event-manager              2.0.1  2.0.1  The Doctrine Event Manager is a simple ...
doctrine/inflector                  2.0.10 2.0.10 PHP Doctrine Inflector is a small libra...
doctrine/instantiator               2.0.0  2.0.0  A small, lightweight utility to instant...
doctrine/lexer                      3.0.1  3.0.1  PHP Doctrine Lexer parser library that ...
doctrine/migrations                 3.7.4  3.7.4  PHP Doctrine Migrations project offer a...
doctrine/orm                        3.2.0  3.2.0  Object-Relational-Mapper for PHP
doctrine/persistence                3.3.3  3.3.3  The Doctrine Persistence project is a s...
doctrine/sql-formatter              1.4.0  1.4.0  a PHP SQL highlighting library

PHP version

$ php -v

PHP 8.2.18 (cli) (built: Apr 11 2024 19:20:54) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.18, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.18, Copyright (c), by Zend Technologies

Subject

After update to latest (3.16.0) version which support ORM 3 there are deprecations appear in symfony debug toolbar.

User Deprecated: Using ArrayAccess on Doctrine\ORM\Mapping\FieldMapping is deprecated and will not be possible in Doctrine ORM 4.0. Use the corresponding property instead. (ArrayAccessImplementation.php:31 called by AbstractAnnotationDriver.php:134, doctrine/orm#11211, package doctrine/orm)

return $mapping && in_array($mapping['type'], self::VALID_TYPES, true);

return $mapping && in_array($mapping['type'], $this->validTypes, true);

etc

@mbabker
Copy link
Contributor

mbabker commented Jun 25, 2024

This is expected behavior right now as a deprecation-free environment would require either dropping ORM 2.x support or adding way too many version checks to the code to avoid them. You can silence these deprecations through Doctrine's deprecations library with this:

use Doctrine\Deprecations\Deprecation;

// Ignore unfixable Doctrine deprecations
Deprecation::ignoreDeprecations(
    'https://github.com/doctrine/orm/pull/11211', // The ORM changed from arrays to named data objects in 3.x, some packages still use array access for B/C
);

@theMadness
Copy link

Any idea of how to implement this suppression while using StofDoctrineExtensionsBundle?

@zorn-v
Copy link
Author

zorn-v commented Jun 26, 2024

either dropping ORM 2.x support or adding way too many version checks to the code to avoid them

Or just search/replace like $mapping['type'] to $mapping->type ?? $mapping['type']

@zorn-v
Copy link
Author

zorn-v commented Jun 26, 2024

Any idea of how to implement this suppression while using StofDoctrineExtensionsBundle?

You can do this in App\Kernel constructor for example

@mbabker
Copy link
Contributor

mbabker commented Jun 26, 2024

either dropping ORM 2.x support or adding way too many version checks to the code to avoid them

Or just search/replace like $mapping['type'] to $mapping->type ?? $mapping['type']

While it looks that simple, it adds a lot of maintenance overhead. A fair number of the uses of the mapping data is in code that runs for both the MongoDB ODM and ORM. ClassMetadata::getFieldMapping() isn't part of the persistence interface, so a consistent type contract doesn't exist. The ODM and ORM 2.x use an array and ORM 3.x uses an object that implements ArrayAccess and triggers deprecations when using array access. The simplest solution right now is to just leave the deprecated array access in place; eventually, someone is going to need to go through all 38 uses of $meta->getFieldMapping() and figure out the context they run in and what the best way to deal with the different type structures is going to be, but given that it's just a deprecation notice and not something that's causing applications to not work (and I get how annoying deprecations can be, I've got dozens of them in the main Symfony application I work on that are unfixable), it's not an extremely urgent thing to address at the moment.

@zorn-v
Copy link
Author

zorn-v commented Jun 26, 2024

Yeah, I'm so brave decided to make pull request 😄
Then I found that it is not so simple.

Maybe use "BC promise", increase major version and cleanup array access then ?

About ODM - just need to kick they )

@Jean85
Copy link

Jean85 commented Oct 16, 2024

The ODM and ORM 2.x use an array and ORM 3.x uses an object that implements ArrayAccess and triggers deprecations when using array access.

I'm probably missing something here, but... doesn't $mapping->type ?? $mapping['type'] avoid triggering the array access if the property is present, hence avoiding both deprecations?

https://3v4l.org/X018d vs https://3v4l.org/NEdul shows how it's a totally doable approach.

@zorn-v
Copy link
Author

zorn-v commented Oct 17, 2024

It avoid, but it is not so simple "find & replace"
Need more brave soldier than I )

@Jean85 Jean85 linked a pull request Oct 18, 2024 that will close this issue
@Jean85
Copy link

Jean85 commented Oct 18, 2024

I did a first attempt to solving this, at least partially, with #2889

@alexislefebvre
Copy link

This is expected behavior right now as a deprecation-free environment would require either dropping ORM 2.x support or adding way too many version checks to the code to avoid them. You can silence these deprecations through Doctrine's deprecations library with this:

use Doctrine\Deprecations\Deprecation;

// Ignore unfixable Doctrine deprecations
Deprecation::ignoreDeprecations(
    'https://github.com/doctrine/orm/pull/11211', // The ORM changed from arrays to named data objects in 3.x, some packages still use array access for B/C
);

Maybe it's obvious but I didn't know where to put this code. I added it to tests/bootstrap.php and it worked.

With Symfony Flex, you should already have this file if you use phpunit/phpunit or symfony/phpunit-bridge.

@endelwar
Copy link

endelwar commented Dec 3, 2024

@alexislefebvre I managed to silence the deprecation by editing src\Kernel.php, extending its constructor

namespace App;

use Doctrine\Deprecations\Deprecation;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;

class Kernel extends BaseKernel
{
    use MicroKernelTrait;

    public function __construct(string $environment, bool $debug)
    {
        parent::__construct($environment, $debug);

        // Ignore unfixable Doctrine deprecations
        Deprecation::ignoreDeprecations(
            'https://github.com/doctrine/orm/pull/11211', // The ORM changed from arrays to named data objects in 3.x, some packages still use array access for B/C
        );
    }
}

@zorn-v
Copy link
Author

zorn-v commented Dec 3, 2024

I added it to tests/bootstrap.php and it worked.

It worked only for tests as this file defined as tests bootstrap in phpunit config by symfony flex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants