Skip to content

Console command can break setup #16173

Closed
Closed
@FreekVandeursen

Description

@FreekVandeursen

Preconditions

  1. Magento 2.2.4
  2. Empty database

Steps to reproduce

  1. Create a module, containing a console command
  2. Use ProductRepositoryInterface in console command constructor
  3. run bin/magento setup:install

Expected result

  1. Setup completing succesfully

Actual result

  1. Database exception, claiming table 'website' does not exist

Analysis

The root cause seems to be in the Magento\Setup\Model\ObjectManagerProvider class, which calls createCliCommands in it's get function. This will break setup when there are any console commands that depend on the database to exist already. I have seen this happen with the ProductRepository for example.

What is the reason for this createCliCommands call? If I just disable that call, the setup will complete succesfully.
It also seems strange that this call is only present in the CLI SAPI, which means functionality is different between CLI or web installation.

Example

<?php
namespace Test\Test\Console\Command;

use Magento\Catalog\Api\ProductRepositoryInterface;
use Symfony\Component\Console\Command\Command;

class TestCommand extends Command
{

    /**
     * @var ProductRepositoryInterface
     */
    private $productRepository;

    public function __construct(
        ProductRepositoryInterface $productRepository,
        string $name = null
    )
    {
        parent::__construct($name);
        $this->productRepository = $productRepository;
    }

    protected function configure()
    {
        $this->setName('test:test')
            ->setDescription('Test command');
        parent::configure();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: Framework/ConsoleIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions