Skip to content

[Issue] AppState emulateAreaCode was not respected by file collector #29656

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

Closed
2 of 4 tasks
m2-assistant bot opened this issue Aug 18, 2020 · 4 comments · Fixed by #28917
Closed
2 of 4 tasks

[Issue] AppState emulateAreaCode was not respected by file collector #29656

m2-assistant bot opened this issue Aug 18, 2020 · 4 comments · Fixed by #28917
Assignees
Labels
Component: View Event: MageCONF CD 2020 Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Priority: P3 May be fixed according to the position in the backlog. Progress: done Reported on 2.4.0 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.

Comments

@m2-assistant
Copy link

m2-assistant bot commented Aug 18, 2020

This issue is automatically created based on existing pull request: #28917: AppState emulateAreaCode was not respected by file collector


Preconditions (*)

Magento 2.4-develop

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.

Steps to reproduce (*)

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,

$data = $this->app_state->emulateAreaCode(   
  \Magento\Framework\App\Area::AREA_ADMINHTML,   
  [$this, "getDataSourceData"],  
  [$field, $args]
);  
  1. Create simple CLI command.
  2. Create \Magento\Framework\View\File\Collector\Base with param ['subDir' => 'ui_component'].

$baseFileCollector = $objectManager->create(Base::class, ['subDir' => 'ui_component']);

  1. Emulates callback inside adminhtml area.

$adminAreaEmulate = $objectManager->create(EmulatedAdminhtmlAreaProcessor::class);
$adminAreaEmulate->process([$baseFileCollector, 'getFiles'], [$theme, '*']);

Actual Result:
As result, we have files only from base area.
view/base/ui_component/*

Expected Result:
As result, we have files from base and adminhtml areas.
view/base/ui_component/*
view/adminhtml/ui_component/*

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 (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)
@m2-assistant m2-assistant bot added Component: View Priority: P3 May be fixed according to the position in the backlog. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. labels Aug 18, 2020
@ghost ghost assigned johan-lindahl Aug 18, 2020
@magento-engcom-team magento-engcom-team added the Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed label Aug 18, 2020
@gwharton
Copy link
Contributor

gwharton commented Aug 29, 2020

I wonder if this is why when running command line apps in 2.4.0 that emulate the FRONTEND AREA, that it cannot find the view.xml file in my theme, and balks trying to generate image urls (as it doesn't know any image sizes in the theme)

@m2-community-project m2-community-project bot added Progress: PR Created Indicates that Pull Request has been created to fix issue and removed Progress: PR in progress labels Sep 24, 2020
@m2-community-project m2-community-project bot added Progress: PR Created Indicates that Pull Request has been created to fix issue and removed Progress: PR Created Indicates that Pull Request has been created to fix issue labels Sep 24, 2020
@engcom-Alfa engcom-Alfa added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch and removed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Oct 20, 2020
@m2-community-project m2-community-project bot added Progress: ready for dev and removed Progress: PR Created Indicates that Pull Request has been created to fix issue labels Oct 20, 2020
@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Oct 20, 2020
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Alfa
Thank you for verifying the issue. Based on the provided information internal tickets MC-38564 were created

Issue Available: @engcom-Alfa, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@magento-engcom-team
Copy link
Contributor

Hi @m2-assistant[bot]. Thank you for your report.
The issue has been fixed in #28917 by @johan-lindahl in 2.4-develop branch
Related commit(s):

The fix will be available with the upcoming 2.4.2 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.4.x The issue has been fixed in 2.4-develop branch label Oct 24, 2020
@magento-engcom-team magento-engcom-team added the Reported on 2.4.0 Indicates original Magento version for the Issue report. label Nov 13, 2020
@richjoregonstate
Copy link

@magento-engcom-team @johan-lindahl

I believe this issue needs to be reopened due to unintended side effects. See: #28917 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: View Event: MageCONF CD 2020 Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Priority: P3 May be fixed according to the position in the backlog. Progress: done Reported on 2.4.0 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants