'Symfony\Component\Console\Exception\LogicException during php bin/console server:run
I cannot run symfony local server by command: php bin/console server:run. I get error: [Symfony\Component\Console\Exception\LogicException] An option named "connection" already exists.
Dependencies in composer.json:
"require": {
"php": "^7.0, <7.4",
"composer/package-versions-deprecated": "^1.11",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
"incenteev/composer-parameter-handler": "^2.0",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^3.0.2",
"symfony/monolog-bundle": "^3.1.0",
"symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.3.10",
"symfony/symfony": "3.3.*",
"twig/twig": "^1.0||^2.0"
},
"require-dev": {
"doctrine/data-fixtures": "^1.3",
"doctrine/doctrine-fixtures-bundle": "^2.3",
"liip/functional-test-bundle": "^1.8",
"phpunit/phpunit": "^6.3",
"sensio/generator-bundle": "^3.0",
"symfony/phpunit-bridge": "^3.0"
},
parameters.yml:
# This file is auto-generated during the composer install
parameters:
database_host: 127.0.0.1
database_port: 3306
database_name: tests
database_user: root
database_password: password
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
secret: ThisTokenIsNotSoSecretChangeIt
I think these parameters in parameters.yml used to work earlier. I use mysql and also sqlite for tests.
Solution 1:[1]
I faced the same issue in a Symfony v4.2 project, without changing anything in my code base.
As already found in this issue https://github.com/doctrine/dbal/issues/4565
it appears in certain versions of the doctrine/doctrine-bundle package (in my case v1.11). The RunSqlDoctrineCommand.php from vendor adds the second option which causes the error.
If you can update your doctrine/doctrine-bundle package, you might be fine. In my case, an update or fix by package was not possible.
What can we do in that case?
What comes next is more a hack, than a real good solution, so use it at your own risk!
As statet in the commit from official repository: https://github.com/doctrine/DoctrineBundle/commit/86d2469d6be06d55ad7b9e2f076f6942476f2e87 (thanks to the guys in issue above)
I made a copy of the new RunSqlDoctrineCommand.php from that commit and save it in my project as dist/RunSqlDoctrineCommand.php.
In composer.json change the scripts sections as follows:
{
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd"
},
"doctrine-bugfix": [
"cp -f dist/RunSqlDoctrineCommand.php vendor/doctrine/doctrine-bundle/Command/Proxy/RunSqlDoctrineCommand.php"
],
"post-install-cmd": [
"@auto-scripts",
"@doctrine-bugfix"
],
"post-update-cmd": [
"@auto-scripts",
"@doctrine-bugfix"
]
}
}
This will just copy and override the original file in vendor directory on every composer install/update. This will only work on a unix/linux system, btw.
As said: Not the best solution, but it keeps your project in shape.
Solution 2:[2]
Solution 3:[3]
Inside (symfony project) vendor/doctrine/doctrine-bundle/Command/Proxy/RunSqlDoctrineCommand.php change configure function like below:
protected function configure()
{
parent::configure();
$this
->setName('doctrine:query:sql')
//->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The
connection to use for this command')
->setHelp(<<<EOT
The <info>%command.name%</info> command executes the given SQL query and
outputs the results:
<info>php %command.full_name% "SELECT * FROM users"</info>
EOT
);
if ($this->getDefinition()->hasOption('connection')) {
return;
}
$this->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The
connection to use for this command');
}
Solution 4:[4]
You can set the 'User-Agent' header to pass that obstacle. Copying user agent value from the actual browser has helped in my case.
If you are using requests, you can set it like this:
res = requests.get('https://www.podchaser.com/lists/best-liberal-politics-podcasts-107a9FVaYE',
headers={'User-Agent': 'Mozilla/5.0 ...'})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sengorius |
| Solution 2 | gerMdz |
| Solution 3 | Rakeshkumar G G |
| Solution 4 | atihonruk |
