This is related to #1405, lack of area code being set during bin/magento setup:upgrade. There are events after the widget save that deal with generating layout xml -- which relies Magento\Theme\Model\View\Design, which then tries to access the current app state area code.
Magento\Framework\Exception\LocalizedException: Area code is not set in /home/samtay/git/sites/RDS/webroot/vendor/magento/framework/App/State.php on line 139
Call Stack:
0.1087 229952 1. {main}() /home/samtay/git/sites/RDS/webroot/bin/magento:0
0.9102 37266416 2. Symfony\Component\Console\Application->run(???, ???) /home/samtay/git/sites/RDS/webroot/bin/magento:25
0.9108 37310032 3. Magento\Framework\Console\Cli->doRun(???, ???) /home/samtay/git/sites/RDS/webroot/vendor/symfony/console/Symfony/Component/Console/Application.php:126
0.9108 37310288 4. Symfony\Component\Console\Application->doRun(???, ???) /home/samtay/git/sites/RDS/webroot/vendor/magento/framework/Console/Cli.php:49
0.9109 37311176 5. Symfony\Component\Console\Application->doRunCommand(???, ???, ???) /home/samtay/git/sites/RDS/webroot/vendor/symfony/console/Symfony/Component/Console/Application.php:195
0.9109 37311648 6. Symfony\Component\Console\Command\Command->run(???, ???) /home/samtay/git/sites/RDS/webroot/vendor/symfony/console/Symfony/Component/Console/Application.php:874
0.9111 37315280 7. Magento\Setup\Console\Command\UpgradeCommand->execute(???, ???) /home/samtay/git/sites/RDS/webroot/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:257
4.2849 87010208 8. Magento\Setup\Model\Installer->installDataFixtures() /home/samtay/git/sites/RDS/webroot/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php:72
4.8371 87140608 9. Magento\Setup\Model\Installer->handleDBSchemaData(???, ???) /home/samtay/git/sites/RDS/webroot/setup/src/Magento/Setup/Model/Installer.php:746
4.8604 87314456 10. BlueAcorn\CustomWidgets\Setup\InstallData->install(???, ???) /home/samtay/git/sites/RDS/webroot/setup/src/Magento/Setup/Model/Installer.php:798
4.9340 89520432 11. Magento\Framework\Model\AbstractModel->save() /home/samtay/git/sites/RDS/webroot/app/code/BlueAcorn/CustomWidgets/Setup/InstallData.php:113
4.9340 89520912 12. Magento\Framework\Model\ResourceModel\Db\AbstractDb->save(???) /home/samtay/git/sites/RDS/webroot/vendor/magento/framework/Model/AbstractModel.php:615
9.7842 89859688 13. Magento\Framework\Model\ResourceModel\Db\AbstractDb->processAfterSaves(???) /home/samtay/git/sites/RDS/webroot/vendor/magento/framework/Model/ResourceModel/Db/AbstractDb.php:408
9.7842 89860144 14. Magento\Widget\Model\ResourceModel\Widget\Instance->_afterSave(???) /home/samtay/git/sites/RDS/webroot/vendor/magento/framework/Model/ResourceModel/Db/AbstractDb.php:828
12.7908 89870472 15. Magento\Widget\Model\ResourceModel\Widget\Instance->_saveLayoutUpdates(???, ???) /home/samtay/git/sites/RDS/webroot/vendor/magento/module-widget/Model/ResourceModel/Widget/Instance.php:78
22.3154 89871744 16. Magento\Widget\Model\Widget\Instance->generateLayoutUpdateXml(???, ???) /home/samtay/git/sites/RDS/webroot/vendor/magento/module-widget/Model/ResourceModel/Widget/Instance.php:124
22.3155 89872656 17. Magento\Framework\View\FileSystem->getTemplateFileName(???, ???) /home/samtay/git/sites/RDS/webroot/vendor/magento/module-widget/Model/Widget/Instance.php:552
22.3155 89873664 18. Magento\Framework\View\Asset\Repository->updateDesignParams(???) /home/samtay/git/sites/RDS/webroot/vendor/magento/framework/View/FileSystem.php:121
22.3193 89917760 19. Magento\Framework\View\Asset\Repository->getDefaultParameter(???) /home/samtay/git/sites/RDS/webroot/vendor/magento/framework/View/Asset/Repository.php:154
22.3193 89917808 20. Magento\Theme\Model\View\Design\Proxy->getDesignParams() /home/samtay/git/sites/RDS/webroot/vendor/magento/framework/View/Asset/Repository.php:167
22.3195 89927704 21. Magento\Theme\Model\View\Design->getDesignParams() /home/samtay/git/sites/RDS/webroot/var/generation/Magento/Theme/Model/View/Design/Proxy.php:159
22.3195 89927816 22. Magento\Theme\Model\View\Design->getArea() /home/samtay/git/sites/RDS/webroot/vendor/magento/module-theme/Model/View/Design.php:264
22.3195 89927880 23. Magento\Framework\App\State->getAreaCode() /home/samtay/git/sites/RDS/webroot/vendor/magento/module-theme/Model/View/Design.php:126
If you need run some code in specific aria you nee use code like
$this->appState->emulateAreaCode(
FrontNameResolver::AREA_CODE,
function() {
// put you code specific code here
}
);
where state is instance of Magento\Framework\App\State class
I would still consider this a bug. Shouldn't have to emulate an area code every time we want to create entities in an InstallData class.
Most helpful comment
I would still consider this a bug. Shouldn't have to emulate an area code every time we want to create entities in an
InstallDataclass.