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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cache] Pdo adapter is still linked with doctrine connection #45407

Closed
Jibbarth opened this issue Feb 12, 2022 · 2 comments
Closed

[Cache] Pdo adapter is still linked with doctrine connection #45407

Jibbarth opened this issue Feb 12, 2022 · 2 comments

Comments

@Jibbarth
Copy link
Contributor

Symfony version(s) affected

6.0

Description

Hi 馃憢

I wanted to add some cache on my database, and try the pdo adapter.

As the doctrine_dbal wasn't yet mentionned in the doc (fixed here), I added the cache.adapter.pdo in a new pool, fetch this pool in a service and try to use it. Got an error while the adapter try to initialize :

image

How to reproduce

Create a little project

composer create-project symfony/skeleton cacheIssue
cd cacheIssue
composer req orm

Config the cache

# config/packages/cache.yaml
framework:
    cache:
        pools:
            db.cache:
                adapter: cache.adapter.pdo

Use it in a new commmand

<?php

namespace App\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Contracts\Cache\CacheInterface;

#[AsCommand(
    name: 'app:cache-test',
)]
class CacheTestCommand extends Command
{
    public function __construct(private CacheInterface $dbCache)
    {
        parent::__construct();
    }


    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $value = $this->dbCache->get('app.hello', fn () => 'Hello from cache');

        $output->writeln($value);

        return Command::SUCCESS;
    }
}

And run it

php bin/console app:cache-test

Possible Solution

Change the default value of default_pdo_provider, whereas I'm not sure what to put here by default if we can't pass anymore the doctrine Connection.

Additional Context

I'm aware now that my mistake was to use this adapter instead cache.adapter.doctrine_dbal in such context, but I think the remaining link between doctrine connection and this pdo adapter should not longer be here by default.

@nicolas-grekas
Copy link
Member

Up for a PR to fix this?

@xabbuh
Copy link
Member

xabbuh commented Mar 4, 2022

see #45637

nicolas-grekas added a commit that referenced this issue Mar 4, 2022
This PR was merged into the 5.4 branch.

Discussion
----------

[Cache] do not pass DBAL connections to PDO adapters

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #45407
| License       | MIT
| Doc PR        |

Commits
-------

1027465 do not pass DBAL connections to PDO adapters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants