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 Magento\Review\Model\ResourceModel\Rating\Option not instantiable in setup scripts #5465

Merged
merged 1 commit into from
Dec 26, 2016

Conversation

adragus-inviqa
Copy link
Contributor

@adragus-inviqa adragus-inviqa commented Jul 5, 2016

Magento\Review\Model\ResourceModel\Rating\Option depends on \Magento\Customer\Model\Session and this makes it not instantiable in setup scripts. By making it a proxy, we're postponing its instantiation.

// some setup script
$optionModel = $objectManager->create(\Magento\Review\Model\Rating\Option::class);

Below is the exceptions triggered when trying to run a setup:upgrade

[Magento\Framework\Exception\SessionException]
  Area code not set: Area code must be set before starting a session.



Exception trace:
 () at /vagrant/vendor/magento/framework/Session/SessionManager.php:175
 Magento\Framework\Session\SessionManager->start() at /vagrant/vendor/magento/framework/Session/SessionManager.php:130
 Magento\Framework\Session\SessionManager->__construct() at /vagrant/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:115
 Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:89
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() at /vagrant/vendor/magento/framework/ObjectManager/ObjectManager.php:71
 Magento\Framework\ObjectManager\ObjectManager->get() at /vagrant/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:236
 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:53
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:82
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() at /vagrant/vendor/magento/framework/ObjectManager/ObjectManager.php:71
 Magento\Framework\ObjectManager\ObjectManager->get() at /vagrant/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:236
 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:53
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:82
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() at /vagrant/vendor/magento/framework/ObjectManager/ObjectManager.php:71
 Magento\Framework\ObjectManager\ObjectManager->get() at /vagrant/vendor/magento/framework/Model/AbstractModel.php:461
 Magento\Framework\Model\AbstractModel->_getResource() at /vagrant/vendor/magento/framework/Model/AbstractModel.php:214
 Magento\Framework\Model\AbstractModel->_init() at /vagrant/vendor/magento/module-review/Model/Rating/Option.php:32
 Magento\Review\Model\Rating\Option->_construct() at /vagrant/vendor/magento/framework/Model/AbstractModel.php:193
 Magento\Framework\Model\AbstractModel->__construct() at /vagrant/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:105
 Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:89
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() at /vagrant/vendor/magento/framework/ObjectManager/ObjectManager.php:57
 Magento\Framework\ObjectManager\ObjectManager->create() at /vagrant/src/Project/Catalog/Setup/data-upgrade/1.1.25.php:56
 include() at /vagrant/src/Project/ModuleSetup/Spi/Updater/SequentialFiles.php:96
 Project\ModuleSetup\Spi\Updater\includeFile() at /vagrant/src/Project/ModuleSetup/Spi/Updater/SequentialFiles.php:88
 Project\ModuleSetup\Spi\Updater\SequentialFiles->update() at /vagrant/src/Project/Catalog/Setup/UpgradeData.php:46
 Project\Catalog\Setup\UpgradeData->upgrade() at /vagrant/setup/src/Magento/Setup/Model/Installer.php:809
 Magento\Setup\Model\Installer->handleDBSchemaData() at /vagrant/setup/src/Magento/Setup/Model/Installer.php:772
 Magento\Setup\Model\Installer->installDataFixtures() at /vagrant/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php:72
 Magento\Setup\Console\Command\UpgradeCommand->execute() at /vagrant/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:257
 Symfony\Component\Console\Command\Command->run() at /vagrant/vendor/symfony/console/Symfony/Component/Console/Application.php:874
 Symfony\Component\Console\Application->doRunCommand() at /vagrant/vendor/symfony/console/Symfony/Component/Console/Application.php:195
 Symfony\Component\Console\Application->doRun() at /vagrant/vendor/magento/framework/Console/Cli.php:49
 Magento\Framework\Console\Cli->doRun() at /vagrant/vendor/symfony/console/Symfony/Component/Console/Application.php:126
 Symfony\Component\Console\Application->run() at /vagrant/bin/magento:25





  [Magento\Framework\Exception\LocalizedException]
  Area code is not set



Exception trace:
 () at /vagrant/vendor/magento/framework/App/State.php:139
 Magento\Framework\App\State->getAreaCode() at /vagrant/vendor/magento/framework/Session/SessionManager.php:173
 Magento\Framework\Session\SessionManager->start() at /vagrant/vendor/magento/framework/Session/SessionManager.php:130
 Magento\Framework\Session\SessionManager->__construct() at /vagrant/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:115
 Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:89
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() at /vagrant/vendor/magento/framework/ObjectManager/ObjectManager.php:71
 Magento\Framework\ObjectManager\ObjectManager->get() at /vagrant/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:236
 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:53
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:82
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() at /vagrant/vendor/magento/framework/ObjectManager/ObjectManager.php:71
 Magento\Framework\ObjectManager\ObjectManager->get() at /vagrant/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:236
 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:53
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:82
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() at /vagrant/vendor/magento/framework/ObjectManager/ObjectManager.php:71
 Magento\Framework\ObjectManager\ObjectManager->get() at /vagrant/vendor/magento/framework/Model/AbstractModel.php:461
 Magento\Framework\Model\AbstractModel->_getResource() at /vagrant/vendor/magento/framework/Model/AbstractModel.php:214
 Magento\Framework\Model\AbstractModel->_init() at /vagrant/vendor/magento/module-review/Model/Rating/Option.php:32
 Magento\Review\Model\Rating\Option->_construct() at /vagrant/vendor/magento/framework/Model/AbstractModel.php:193
 Magento\Framework\Model\AbstractModel->__construct() at /vagrant/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:105
 Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:89
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() at /vagrant/vendor/magento/framework/ObjectManager/ObjectManager.php:57
 Magento\Framework\ObjectManager\ObjectManager->create() at /vagrant/src/Project/Catalog/Setup/data-upgrade/1.1.25.php:56
 include() at /vagrant/src/Project/ModuleSetup/Spi/Updater/SequentialFiles.php:96
 Project\ModuleSetup\Spi\Updater\includeFile() at /vagrant/src/Project/ModuleSetup/Spi/Updater/SequentialFiles.php:88
 Project\ModuleSetup\Spi\Updater\SequentialFiles->update() at /vagrant/src/Project/Catalog/Setup/UpgradeData.php:46
 Project\Catalog\Setup\UpgradeData->upgrade() at /vagrant/setup/src/Magento/Setup/Model/Installer.php:809
 Magento\Setup\Model\Installer->handleDBSchemaData() at /vagrant/setup/src/Magento/Setup/Model/Installer.php:772
 Magento\Setup\Model\Installer->installDataFixtures() at /vagrant/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php:72
 Magento\Setup\Console\Command\UpgradeCommand->execute() at /vagrant/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:257
 Symfony\Component\Console\Command\Command->run() at /vagrant/vendor/symfony/console/Symfony/Component/Console/Application.php:874
 Symfony\Component\Console\Application->doRunCommand() at /vagrant/vendor/symfony/console/Symfony/Component/Console/Application.php:195
 Symfony\Component\Console\Application->doRun() at /vagrant/vendor/magento/framework/Console/Cli.php:49
 Magento\Framework\Console\Cli->doRun() at /vagrant/vendor/symfony/console/Symfony/Component/Console/Application.php:126
 Symfony\Component\Console\Application->run() at /vagrant/bin/magento:25

… in setup scripts

`Magento\Review\Model\ResourceModel\Rating\Option` depends on `\Magento\Customer\Model\Session` and this makes it not instantiable in setup scripts. By making it a proxy, we're postponing its instantiation.

```php
// some setup script
$optionModel = $objectManager->create(Magento\Review\Model\Rating\Option::class);
```

Below is the exceptions triggered when trying to run a `setup:upgrade`
```
[Magento\Framework\Exception\SessionException]
  Area code not set: Area code must be set before starting a session.



Exception trace:
 () at /vagrant/vendor/magento/framework/Session/SessionManager.php:175
 Magento\Framework\Session\SessionManager->start() at /vagrant/vendor/magento/framework/Session/SessionManager.php:130
 Magento\Framework\Session\SessionManager->__construct() at /vagrant/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:115
 Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:89
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() at /vagrant/vendor/magento/framework/ObjectManager/ObjectManager.php:71
 Magento\Framework\ObjectManager\ObjectManager->get() at /vagrant/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:236
 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:53
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:82
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() at /vagrant/vendor/magento/framework/ObjectManager/ObjectManager.php:71
 Magento\Framework\ObjectManager\ObjectManager->get() at /vagrant/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:236
 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:53
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:82
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() at /vagrant/vendor/magento/framework/ObjectManager/ObjectManager.php:71
 Magento\Framework\ObjectManager\ObjectManager->get() at /vagrant/vendor/magento/framework/Model/AbstractModel.php:461
 Magento\Framework\Model\AbstractModel->_getResource() at /vagrant/vendor/magento/framework/Model/AbstractModel.php:214
 Magento\Framework\Model\AbstractModel->_init() at /vagrant/vendor/magento/module-review/Model/Rating/Option.php:32
 Magento\Review\Model\Rating\Option->_construct() at /vagrant/vendor/magento/framework/Model/AbstractModel.php:193
 Magento\Framework\Model\AbstractModel->__construct() at /vagrant/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:105
 Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:89
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() at /vagrant/vendor/magento/framework/ObjectManager/ObjectManager.php:57
 Magento\Framework\ObjectManager\ObjectManager->create() at /vagrant/src/Project/Catalog/Setup/data-upgrade/1.1.25.php:56
 include() at /vagrant/src/Project/ModuleSetup/Spi/Updater/SequentialFiles.php:96
 Project\ModuleSetup\Spi\Updater\includeFile() at /vagrant/src/Project/ModuleSetup/Spi/Updater/SequentialFiles.php:88
 Project\ModuleSetup\Spi\Updater\SequentialFiles->update() at /vagrant/src/Project/Catalog/Setup/UpgradeData.php:46
 Project\Catalog\Setup\UpgradeData->upgrade() at /vagrant/setup/src/Magento/Setup/Model/Installer.php:809
 Magento\Setup\Model\Installer->handleDBSchemaData() at /vagrant/setup/src/Magento/Setup/Model/Installer.php:772
 Magento\Setup\Model\Installer->installDataFixtures() at /vagrant/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php:72
 Magento\Setup\Console\Command\UpgradeCommand->execute() at /vagrant/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:257
 Symfony\Component\Console\Command\Command->run() at /vagrant/vendor/symfony/console/Symfony/Component/Console/Application.php:874
 Symfony\Component\Console\Application->doRunCommand() at /vagrant/vendor/symfony/console/Symfony/Component/Console/Application.php:195
 Symfony\Component\Console\Application->doRun() at /vagrant/vendor/magento/framework/Console/Cli.php:49
 Magento\Framework\Console\Cli->doRun() at /vagrant/vendor/symfony/console/Symfony/Component/Console/Application.php:126
 Symfony\Component\Console\Application->run() at /vagrant/bin/magento:25





  [Magento\Framework\Exception\LocalizedException]
  Area code is not set



Exception trace:
 () at /vagrant/vendor/magento/framework/App/State.php:139
 Magento\Framework\App\State->getAreaCode() at /vagrant/vendor/magento/framework/Session/SessionManager.php:173
 Magento\Framework\Session\SessionManager->start() at /vagrant/vendor/magento/framework/Session/SessionManager.php:130
 Magento\Framework\Session\SessionManager->__construct() at /vagrant/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:115
 Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:89
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() at /vagrant/vendor/magento/framework/ObjectManager/ObjectManager.php:71
 Magento\Framework\ObjectManager\ObjectManager->get() at /vagrant/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:236
 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:53
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:82
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() at /vagrant/vendor/magento/framework/ObjectManager/ObjectManager.php:71
 Magento\Framework\ObjectManager\ObjectManager->get() at /vagrant/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:236
 Magento\Framework\ObjectManager\Factory\AbstractFactory->resolveArgument() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:53
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->_resolveArguments() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:82
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() at /vagrant/vendor/magento/framework/ObjectManager/ObjectManager.php:71
 Magento\Framework\ObjectManager\ObjectManager->get() at /vagrant/vendor/magento/framework/Model/AbstractModel.php:461
 Magento\Framework\Model\AbstractModel->_getResource() at /vagrant/vendor/magento/framework/Model/AbstractModel.php:214
 Magento\Framework\Model\AbstractModel->_init() at /vagrant/vendor/magento/module-review/Model/Rating/Option.php:32
 Magento\Review\Model\Rating\Option->_construct() at /vagrant/vendor/magento/framework/Model/AbstractModel.php:193
 Magento\Framework\Model\AbstractModel->__construct() at /vagrant/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:105
 Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject() at /vagrant/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:89
 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() at /vagrant/vendor/magento/framework/ObjectManager/ObjectManager.php:57
 Magento\Framework\ObjectManager\ObjectManager->create() at /vagrant/src/Project/Catalog/Setup/data-upgrade/1.1.25.php:56
 include() at /vagrant/src/Project/ModuleSetup/Spi/Updater/SequentialFiles.php:96
 Project\ModuleSetup\Spi\Updater\includeFile() at /vagrant/src/Project/ModuleSetup/Spi/Updater/SequentialFiles.php:88
 Project\ModuleSetup\Spi\Updater\SequentialFiles->update() at /vagrant/src/Project/Catalog/Setup/UpgradeData.php:46
 Project\Catalog\Setup\UpgradeData->upgrade() at /vagrant/setup/src/Magento/Setup/Model/Installer.php:809
 Magento\Setup\Model\Installer->handleDBSchemaData() at /vagrant/setup/src/Magento/Setup/Model/Installer.php:772
 Magento\Setup\Model\Installer->installDataFixtures() at /vagrant/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php:72
 Magento\Setup\Console\Command\UpgradeCommand->execute() at /vagrant/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:257
 Symfony\Component\Console\Command\Command->run() at /vagrant/vendor/symfony/console/Symfony/Component/Console/Application.php:874
 Symfony\Component\Console\Application->doRunCommand() at /vagrant/vendor/symfony/console/Symfony/Component/Console/Application.php:195
 Symfony\Component\Console\Application->doRun() at /vagrant/vendor/magento/framework/Console/Cli.php:49
 Magento\Framework\Console\Cli->doRun() at /vagrant/vendor/symfony/console/Symfony/Component/Console/Application.php:126
 Symfony\Component\Console\Application->run() at /vagrant/bin/magento:25
```
@vkorotun vkorotun added Component: Customer Progress: accept bug report Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bugfix and removed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report labels Aug 3, 2016
@sshrewz
Copy link

sshrewz commented Aug 11, 2016

Internal ticket - MAGETWO-56793

@sshrewz sshrewz added the linked label Aug 11, 2016
@vkorotun vkorotun added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development and removed linked labels Aug 22, 2016
@mmansoor-magento mmansoor-magento merged commit 30dd1d9 into magento:develop Dec 26, 2016
mmansoor-magento pushed a commit that referenced this pull request Dec 26, 2016
[SOUTH] Bugs:
- MAGETWO-52925 Simple child product without a special price still shown as "was (original price)" #4442 #5097 #6645 - for mainline
- MAGETWO-60098 Configurable product option price is displayed incorrectly per website
- MAGETWO-56793 [GITHUB][PR] Fix Magento\Review\Model\ResourceModel\Rating\Option not instantiable in setup scripts #5465
- MAGETWO-58078 [FT] CreateProductAttributeEntityFromProductPageTest fails
- MAGETWO-61725 [GITHUB] Improve address save flow to allow to use custom validators #7552
@adragus-inviqa adragus-inviqa deleted the patch-5 branch January 10, 2017 10:03
@Ctucker9233
Copy link

@mmansoorebay @vkorotun Any idea what version of Magento will include this fix?

@Ctucker9233
Copy link

Still not in 2.1.10...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Component: Customer Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Progress: accept
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants