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

Fix compatibility layer for cache services #1352

Merged
merged 8 commits into from
Jun 1, 2021
Merged

Fix compatibility layer for cache services #1352

merged 8 commits into from
Jun 1, 2021

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented May 25, 2021

Due to container isolation, we cannot access the definition of the given cache service, which breaks autodetection. Thus, we introduce a new is_psr configuration option to be used with cache services for people to indicate that they are using a PSR-6 cache service.

Includes the test from #1350 in addition to another functional test for a PSR-6 service.

@alcaeus alcaeus added the Bug label May 25, 2021
@alcaeus alcaeus added this to the 2.4.0 milestone May 25, 2021
@alcaeus alcaeus self-assigned this May 25, 2021
@alcaeus alcaeus force-pushed the bug-1348 branch 2 times, most recently from f366db2 to 1b9bcd1 Compare May 25, 2021 10:00
@alcaeus alcaeus requested a review from stof May 25, 2021 12:19
DependencyInjection/Configuration.php Outdated Show resolved Hide resolved
DependencyInjection/Configuration.php Outdated Show resolved Hide resolved
Tests/DependencyInjection/DoctrineExtensionTest.php Outdated Show resolved Hide resolved
Copy link
Member

@ostrolucky ostrolucky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also UPGRADE-2.4.md should be updated

composer.json Outdated Show resolved Hide resolved
@alcaeus
Copy link
Member Author

alcaeus commented May 25, 2021

I'll make another attempt at auto-detecting this using a compiler pass...tomorrow 😉

@ostrolucky
Copy link
Member

I've pushed a commit which fixes this via compiler pass instead. Would be great if you guys would review & test this, so that we can merge this and release 2.4 soon.

@dmaicher
Copy link
Contributor

@ostrolucky I just tested it and it works nicely except for one case

I tried this config using a doctrine/cache service for metadata caching

    orm:
        default_entity_manager: default
        entity_managers:
            default:
                metadata_cache_driver:
                    type: service
                    id: my.doctrine.cache

this works fine for debug cases but fails for no-debug (when the PhpArrayAdapter is used):

    $ app/console cache:clear --no-debug -vvv
        
        // Clearing the cache for the dev environment with debug false
        
        // Clearing outdated warmup directory...
        
        // Warming up cache...
    
    
    In PhpArrayAdapter.php line 48:
      
      [TypeError]
          Argument 2 passed to Symfony\Component\Cache\Adapter\PhpArrayAdapter::__construct() must implement interface Symfony\Component\Cache\Adapter\AdapterInterface, instance of Symfony\Component\Cache\DoctrinePro
          vider given, called in /var/www/test/symfony/app/cache/de_/ContainerBPTxcrq/appAppKernelDevContainer.php on line 1716
    
    
    Exception trace:
        at /var/www/test/symfony/vendor/symfony/cache/Adapter/PhpArrayAdapter.php:48
        Symfony\Component\Cache\Adapter\PhpArrayAdapter->__construct() at /var/www/test/symfony/app/cache/de_/ContainerBPTxcrq/appAppKernelDevContainer.php:1716
        ContainerBPTxcrq\appAppKernelDevContainer->getDoctrine_Orm_DefaultEntityManagerService() at /var/www/test/symfony/app/cache/de_/ContainerBPTxcrq/appAppKernelDevContainer.php:1654
        ContainerBPTxcrq\appAppKernelDevContainer->ContainerBPTxcrq\{closure}() at /var/www/test/symfony/app/cache/de_/ContainerBPTxcrq/EntityManager_9a5be93.php:22
        Closure->__invoke() at /var/www/test/symfony/app/cache/de_/ContainerBPTxcrq/EntityManager_9a5be93.php:22
        ContainerBPTxcrq\EntityManager_9a5be93->getMetadataFactory() at /var/www/test/symfony/vendor/doctrine/doctrine-bundle/CacheWarmer/DoctrineMetadataCacheWarmer.php:47
        Doctrine\Bundle\DoctrineBundle\CacheWarmer\DoctrineMetadataCacheWarmer->doWarmUp() at /var/www/test/symfony/vendor/symfony/framework-bundle/CacheWarmer/AbstractPhpFileCacheWarmer.php:49
        Symfony\Bundle\FrameworkBundle\CacheWarmer\AbstractPhpFileCacheWarmer->warmUp() at /var/www/test/symfony/vendor/symfony/http-kernel/CacheWarmer/CacheWarmerAggregate.php:97
        Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp() at /var/www/test/symfony/vendor/symfony/http-kernel/Kernel.php:633
        Symfony\Component\HttpKernel\Kernel->initializeContainer() at /var/www/test/symfony/vendor/symfony/http-kernel/Kernel.php:136
        Symfony\Component\HttpKernel\Kernel->boot() at /var/www/test/symfony/vendor/symfony/http-kernel/Kernel.php:153
        Symfony\Component\HttpKernel\Kernel->reboot() at /var/www/test/symfony/vendor/symfony/framework-bundle/Command/CacheClearCommand.php:189
        Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->warmup() at /var/www/test/symfony/vendor/symfony/framework-bundle/Command/CacheClearCommand.php:129
        Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->execute() at /var/www/test/symfony/vendor/symfony/console/Command/Command.php:255
        Symfony\Component\Console\Command\Command->run() at /var/www/test/symfony/vendor/symfony/console/Application.php:1027
        Symfony\Component\Console\Application->doRunCommand() at /var/www/test/symfony/vendor/symfony/framework-bundle/Console/Application.php:97
        Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /var/www/test/symfony/vendor/symfony/console/Application.php:273
        Symfony\Component\Console\Application->doRun() at /var/www/test/symfony/vendor/symfony/framework-bundle/Console/Application.php:83
        Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/test/symfony/vendor/symfony/console/Application.php:149
        Symfony\Component\Console\Application->run() at /var/www/test/symfony/app/console:35

@alexander-schranz
Copy link
Contributor

Same error for me as @dmaicher when running bin/console cache:clear --env prod on sulu/sulu. Tested with Symfony 5.2.9 and 5.3.0-dev both output the following:

Output:
PHP Fatal error:  Uncaught TypeError: Argument 2 passed to Symfony\Component\Cache\Adapter\PhpArrayAdapter::__construct() must implement interface Symfony\Component\Cache\Adapter\AdapterInterface, instance of Symfony\Component\Cache\DoctrineProvider given, called in /Users/me/Documents/Sulu/sulu-develop.localhost/vendor/sulu/sulu/var/cache/admin/prod/ContainerKCQGinW/App_KernelProdContainer.php on line 886 and defined in /Users/me/Documents/Sulu/sulu-develop.localhost/vendor/sulu/sulu/vendor/symfony/cache/Adapter/PhpArrayAdapter.php:48
Stack trace:
#0 /Users/me/Documents/Sulu/sulu-develop.localhost/vendor/sulu/sulu/var/cache/admin/prod/ContainerKCQGinW/App_KernelProdContainer.php(886): Symfony\Component\Cache\Adapter\PhpArrayAdapter->__construct('/Users/me...', Object(Symfony\Component\Cache\DoctrineProvider))
#1 /Users/me/Documents/Sulu/sulu-develop.localhost/vendor/sulu/sulu/var/cache/admin/prod/ContainerKCQGinW/App_KernelProdContainer.php(829): ContainerKCQGinW\A in /Users/me/Documents/Sulu/sulu-develop.localhost/vendor/sulu/sulu/vendor/symfony/cache/Adapter/PhpArrayAdapter.php on line 48

Fatal error: Uncaught TypeError: Argument 2 passed to Symfony\Component\Cache\Adapter\PhpArrayAdapter::__construct() must implement interface Symfony\Component\Cache\Adapter\AdapterInterface, instance of Symfony\Component\Cache\DoctrineProvider given, called in /Users/me/Documents/Sulu/sulu-develop.localhost/vendor/sulu/sulu/var/cache/admin/prod/ContainerKCQGinW/App_KernelProdContainer.php on line 886 and defined in /Users/me/Documents/Sulu/sulu-develop.localhost/vendor/sulu/sulu/vendor/symfony/cache/Adapter/PhpArrayAdapter.php:48
Stack trace:
#0 /Users/me/Documents/Sulu/sulu-develop.localhost/vendor/sulu/sulu/var/cache/admin/prod/ContainerKCQGinW/App_KernelProdContainer.php(886): Symfony\Component\Cache\Adapter\PhpArrayAdapter->__construct('/Users/me...', Object(Symfony\Component\Cache\DoctrineProvider))
#1 /Users/me/Documents/Sulu/sulu-develop.localhost/vendor/sulu/sulu/var/cache/admin/prod/ContainerKCQGinW/App_KernelProdContainer.php(829): ContainerKCQGinW\A in /Users/me/Documents/Sulu/sulu-develop.localhost/vendor/sulu/sulu/vendor/symfony/cache/Adapter/PhpArrayAdapter.php on line 48

@ostrolucky
Copy link
Member

Thx for feedback. This should be now fixed

@alexander-schranz
Copy link
Contributor

@ostrolucky can confirm it is fixed for me now!

@alcaeus alcaeus requested a review from ostrolucky May 31, 2021 11:50
@ostrolucky ostrolucky merged commit e4ba833 into 2.4.x Jun 1, 2021
@Gemorroj
Copy link

Gemorroj commented Jun 1, 2021

framework:
    cache:
        pools:
            doctrine.result_cache_pool:
                adapter: cache.adapter.filesystem

doctrine:
    orm:
        result_cache_driver:
            type: pool
            pool: doctrine.result_cache_pool
Argument 1 passed to Doctrine\DBAL\Configuration::setResultCacheImpl() must implement interface Doctrine\Common\Cache\Cache, instance of Symfony\Component\Cache\Adapter\FilesystemAdapter given

@alcaeus alcaeus deleted the bug-1348 branch June 1, 2021 16:45
@ostrolucky
Copy link
Member

@Gemorroj thanks for quick report (although report via issue would be better). Can you try #1360?

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

Successfully merging this pull request may close these issues.

6 participants