-
Notifications
You must be signed in to change notification settings - Fork 9.4k
AppState emulateAreaCode was not respected by file collector #28917
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
AppState emulateAreaCode was not respected by file collector #28917
Conversation
Hi @johan-lindahl. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
You can find more information about the builds here ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review. For more details, please, review the Magento Contributor Guide documentation. |
@magento run all tests |
…agento2 into bugfix-emulate-area-code
@magento run all tests |
@magento create issue |
I dont know if it is related, but I when running bin/magento console apps that emulate AREA_FRONTEND, the /etc/view.xml file is not read from your theme when you attempt to do anything theme related, e.g simply getting the viewConfig item results in a merged object of all enabled modules etc/view.xml but the content from the themes view.xml is missing. |
Hi @lenaorobei, thank you for the review.
|
Dev experience is required for testing of this PR. Please note that Manual testing has not been performed. |
✔️ QA Passed
Before: After |
Hi @johan-lindahl, thank you for your contribution! |
@magento-engcom-team @johan-lindahl @lenaorobei It looks like this fix has a few more consequences then intended. My team just finished an upgrade from 2.3.5 -> 2.4.3 (enterprise) and we now get an "Area code not set" any time we run a cli command. Upon investigation we found that the change from The large difference between the two is that I do believe that the switch to try {
$area = $theme->getArea();
$themeFiles = $this->componentDirSearch->collectFilesWithContext(
ComponentRegistrar::MODULE,
"view/{$area}/{$this->subDir}{$filePath}"
);
foreach ($themeFiles as $file) {
$result[] = $this->fileFactory->create($file->getFullPath(), $file->getComponentName());
}
}
catch (\Magento\Framework\Exception\LocalizedException $e ) {
... // Warning area code not set
} // Otherwise fail normally *The file path looks like "view//{$this->subDir}{$filePath}" which is invalid due to "//". |
Thanks @richjoregonstate for reporting We are upgrading from 2.4.1 to 2.4.3 and facing this issue too. |
@richjoregonstate: would you be so kind to send in a PR with your suggestion so it can be followed up properly, otherwise your comment might be forgotten, thanks! 🙂 |
We are experiencing the same issue "Area code is not set" while updating modules during the upgrade from 2.3.6->2.4.3-p1 |
@hostep thanks, that worked like a charm in my case, without extra try-catch block. |
Description (*)
The "hack" to emulate an area code via AppState->emulateAreaCode() is not respected by the base file collector. The consequence is that *.xml file in the emulated area is not found by the file collector.
Related Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
The problem occurs in an extension I have built that require to access the adminhtml area from the graphql area. There are likely other modules in the Magento 2 that suffers from the same problem. However I can not point one such module without spending a considerable amount of time searching for it.
The following snippet suffer from this bug,
Questions or comments
I thinks someone more knowledgable should look into this issue. I have troubleshooted and my conclusions are as follows.
The base file collector is accessing the area code of the Theme with a call to getData('area').
The Theme has an override called getArea(), this method is never called by the base file collector.
This causes problems for modules that use "emulated area codes" via the
\Magento\Framework\App\State->emulateAreaCode() method.
The emulated area code is then not respected by the file collector since it access the data directly and not via the intended getArea() method in the Theme.
Contribution checklist (*)
Resolved issues: