Description
Preconditions
Steps to reproduce
- Upgrading a store via composer. Version Magento 2.2.2 to Magento 2.2.5
- Run
composer update -vvv
- Apply 2 patches: CE-MAGETWO-93036-2018-07-02-07-06-53.patch and htdocs/CE-MAGETWO-93083-COMPOSER-2018-07-16-03-39-02.patch
- Run
php bin/magento setup:upgrade
- When Magento_Sales upgrades, in
UpgradeData.php
, functionfillQuoteAddressIdInSalesOrderAddress()
throws an errorArea code is not set
.
Expected result
- No error
Actual result
php bin/magento setup:upgrade
fails
I guess I've been doing the upgrade slightly differently.
I run php bin/magento setup:upgrade
after applying the 2 patches.
In future releases, upgrading from a previous Magento 2 version could fail because of this error.
The error is triggered in vendor/magento/framework/Session/SidResolver.php
, function getSid():
Magento\Framework\Session\SidResolver\Proxy->getSid(Object(Magento\Framework\Session\Generic\Interceptor))
Magento\Framework\Session\SidResolver->getSid(Object(Magento\Framework\Session\Generic\Interceptor))
Magento\Framework\App\State->getAreaCode()
Even if fillQuoteAddressIdInSalesOrderAddress is called in an emulated area with area code set:
$this->state->emulateAreaCode(
\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE,
[$this, 'fillQuoteAddressIdInSalesOrderAddress'],
[$setup]
);
it stills fails because in Magento\Framework\Session\SidResolver $this->appState is a Magento style "singleton"/shared class:
$this->appState = $appState ?: \Magento\Framework\App\ObjectManager::getInstance()->get(State::class);
where in UpgradeData.php
, $this->state is a new instance of the same class.
Area code is not seen in $this->appState from SidResolver class.
I guess the fix is something like:
$this->state = \Magento\Framework\App\ObjectManager::getInstance()->get(State::class);
in __construct()
, vendor/magento/module-sales/Setup/UpgradeData.php
.
Or declare the state
parameter as shared in di.xml, arguments of UpgradeData.php.
This works for me. I am not assuming it is a perfect solution that does not has the potential to impact the other Magento 2 modules setup upgrade.