Skip to content

Upgrade to Magento 2.2.5 with patches in place. Area code is not set in Magento_Sales fillQuoteAddressIdInSalesOrderAddress #17434

Closed
@daniel-ifrim

Description

@daniel-ifrim

Preconditions

Steps to reproduce

  1. Upgrading a store via composer. Version Magento 2.2.2 to Magento 2.2.5
  2. Run composer update -vvv
  3. 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
  4. Run php bin/magento setup:upgrade
  5. When Magento_Sales upgrades, in UpgradeData.php, function fillQuoteAddressIdInSalesOrderAddress() throws an error Area code is not set.

Expected result

  1. No error

Actual result

  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: SalesIssue: 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