Skip to content

Don't assume a frontend cache section exists in the env.php file. #38119

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

Merged

Conversation

hostep
Copy link
Contributor

@hostep hostep commented Oct 24, 2023

Description (*)

Code exists in Magento that assumes your app/etc/env.php will always contain a frontend section if there is a cache section. Like this:

    'cache' => [
        'frontend' => [
            ...
        ]
     ]

But that's not always the case. All shops that were setup before Magento 2.3.1 didn't have a cache section in their env.php file in a default installation (if they didn't use Redis as caching).
If they now upgrade to Magento 2.4.4 or higher and use a graphql endpoint, Magento automatically writes cache > graphql > id_salt to the env.php file and so introduces a cache section without a frontend section.

This then leads to this crash on every execution within Magento (frontend, backoffice, bin/magento, ...):

Warning: Undefined array key "frontend" in lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php on line 90

This PR fixes this.

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes [2.4.4] Missing Frontend CacheInfo breaks bin/magento #35812
  2. Fixes graphql id_salt causing 500 server errors #35861

Manual testing scenarios (*)

  1. Fully setup a working Magento
  2. Edit the app/etc/env.php file and remove the entire frontend section in the cache section
  3. Run bin/magento or visit the frontend
  4. Expected is to not see an error/crash
  5. Run added unit test with and without fix. Without the fix, the test will fail (vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php)

More elaborate testing scenario that can cause this situation:

  1. Using PHP 7.2 and composer v1, setup Magento 2.3.0 and install it fully (don't configure it with Redis caching)
  2. Double check that the app/etc/env.php file contains no cache section
  3. Using PHP 8.2 and composer v2, upgrade this installation to Magento 2.4.6-p3 (or 2.4-develop)
  4. Run bin/magento setup:upgrade
  5. Your app/etc/env.php file will be updated to a new format, but will still not contain a cache section.
  6. Confirm that Magento works correctly
  7. On the frontend visit the /graphql url
  8. Check your app/etc/env.php file and see that a cache section has appeared with a graphql section but no frontend section
  9. Visit the homepage or run bin/magento
  10. See errors/crashes

Questions or comments

Should we expect that when we run bin/magento setup:upgrade it will update your app/etc/env.php file with all missing sections? Would people expect this? Or will this cause issues in some scenario's? Running bin:magento setup:config:set without extra flags does exactly that. That seems to be some kind of hidden feature ...

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)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Resolved issues:

  1. resolves [Issue] Don't assume a frontend cache section exists in the env.php file. #38363: Don't assume a frontend cache section exists in the env.php file.

@m2-assistant
Copy link

m2-assistant bot commented Oct 24, 2023

Hi @hostep. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.

Add the comment under your pull request to deploy test or vanilla Magento instance:
  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@hostep hostep marked this pull request as ready for review October 24, 2023 19:48
@hostep
Copy link
Contributor Author

hostep commented Oct 24, 2023

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@hostep hostep force-pushed the fix-for-issue-35812 branch from 6aed4dd to 8b62461 Compare October 24, 2023 20:28
@hostep
Copy link
Contributor Author

hostep commented Oct 24, 2023

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@engcom-Bravo engcom-Bravo added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Oct 25, 2023
@Den4ik Den4ik self-requested a review November 13, 2023 09:55
@swnsma swnsma self-requested a review November 14, 2023 14:34
@swnsma swnsma self-assigned this Nov 14, 2023
@swnsma
Copy link
Contributor

swnsma commented Nov 15, 2023

@magento run all tests

Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@swnsma
Copy link
Contributor

swnsma commented Nov 15, 2023

@magento run Functional Tests B2B,Functional Tests CE

Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@swnsma
Copy link
Contributor

swnsma commented Nov 15, 2023

@magento run Functional Tests B2B,Functional Tests CE

Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@swnsma
Copy link
Contributor

swnsma commented Nov 15, 2023

@magento run Functional Tests CE

Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@sinhaparul sinhaparul added the Project: Community Picked PRs upvoted by the community label Nov 17, 2023
@engcom-Delta engcom-Delta added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Nov 21, 2023
@engcom-Hotel engcom-Hotel self-assigned this Nov 21, 2023
@engcom-Hotel
Copy link
Contributor

@magento run all tests

Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@engcom-Hotel
Copy link
Contributor

✔️ QA Passed

Preconditions:
Fully set-up a working Magento

Manual testing scenario:

  1. Edit the app/etc/env.php file and remove the entire frontend section in the cache section
  2. Run bin/magento or visit the frontend
  3. . Expected is to not see an error/crash
  4. Run added unit test with and without fix. Without the fix, the test will fail
    (vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist lib/internal/Magento/Framework/App/Test/Unit/Cache/Frontend/PoolTest.php)

Actual Result: ✔️
The valid home page should be visible in the browser.

After: ✔️
The valid home page should be visible in the browser.
image

Before: ✖️
image

image

Tested all the manual scenarios, no impact on regression testing.

@engcom-Hotel
Copy link
Contributor

@magento create issue

@hostep
Copy link
Contributor Author

hostep commented Jan 18, 2024

@engcom-Hotel: you realize that this was already approved and merged? :p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: accept Project: Community Picked PRs upvoted by the community Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
None yet
8 participants