Skip to content
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

Fixes problem with latest versions of ICU library where AmPmMarkers i… #38364

Merged

Conversation

hostep
Copy link
Contributor

@hostep hostep commented Jan 18, 2024

…s no longer defined for each locale. If that's the case fall back to AmPmMarkersAbbr and if that one doesn't exist, fallback to null. This fixes a second problem where previously we always returned 'null' due to the index being a string instead of an integer. That's also fixed now.

Description (*)

See discussions in #38214

The second commit in this PR is to deal with static test failures where a method can contain at most 100 lines, which we just managed to reach with the change in the first commit.

I think this is quite an important fix, because an update of the ICU library on a server will start crashing the shop on every frontend page that contains a JS calendar widget. So if a Linux operating system decides to upgrade to a different version of ICU, your shop might be in trouble despite no other changes have being made to it. Which could be surprising to the merchant & developers.
Maybe it's worth turning this into a quality patch as every Magento version might run into this issue one day or another.

Here's an example of how this data is defined in ICU:

This PR fixes the problem mentioned in the issue and fixes a second bug that has existed since forever in Magento where we always outputted null to the am & pm variables that get exposed in the phtml files that use this block. This was due to using ['0'] and ['1'] instead of [0] & [1]

After some thinking, I decided to implement a fallback system, where we first try to fetch AmPmMarkers. If that doesn't exists, try fetching AmPmMarkersAbbr and if that doesn't exists, fallback to null.

As far as I can see, these am and pm variable assignments aren't used in core Magento, but are send to the calendar.phtml file and can be outputted with <?= $am; ?> and <?= $pm; ?>. So that if custom theme needs this info, they can use it.

I've added some more locale's to be tested in the unit tests, those will also fail without the fixes proposed here when the ICU library is 74.1 or 74.2

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes Exception: Warning: Trying to access array offset in... -> Calendar.php since upgrade to ICU 74.1 (PHP Intl) #38214

Manual testing scenarios (*)

  1. Setup clean Magento
  2. In backoffice, go to Stores > Attributes > Product
  3. Find and edit the special_from_date attribute
  4. Under Storefront Properties, enable both 'Use in Search' and 'Visible in Advanced Search' and save the attribute
  5. Reindex
  6. Edit the file app/code/Magento/Theme/view/frontend/templates/js/calendar.phtml and add this line at the very bottom: <ul><li>am: <?= $am; ?></li><li>pm: <?= $pm; ?></li></ul>
  7. Configure "lv_LV" locale: bin/magento config:set general/locale/code lv_LV
  8. Flush the caches
  9. In frontend click on the Advanced Search link in the footer
  10. Expected to see "priekšpusdienā" & "pēcpusdienā" (but then escaped for JS)
  11. Configure "sv_SE" locale: bin/magento config:set general/locale/code sv_SE
  12. Flush the caches
  13. In frontend click on the Advanced Search link in the footer
  14. Expected to see "fm" & "em"
  15. Configure "de_AT" locale: bin/magento config:set general/locale/code de_AT
  16. Flush the caches
  17. In frontend click on the Advanced Search link in the footer
  18. Expected to see "null" & "null"

The biggest thing to check for is that this page doesn't crash. It will not crash with older versions of the ICU library but will crash without these fixes with ICU 74.1 or 74.2. The output for "de_AT" will also be different when using older versions of the ICU library.

Questions or comments

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)

Copy link

m2-assistant bot commented Jan 18, 2024

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
Copy link
Contributor Author

hostep commented Jan 18, 2024

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

…s no longer defined for each locale. If that's the case fall back to AmPmMarkersAbbr and if that one doesn't exist, fallback to null. This fixes a second problem where previously we always returned 'null' due to the index being a string instead of an integer. That's also fixed now.
@hostep hostep force-pushed the fix-for-issue-38214 branch from 88446a5 to a9aab20 Compare January 18, 2024 20:34
@hostep
Copy link
Contributor Author

hostep commented Jan 18, 2024

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

@hostep
Copy link
Contributor Author

hostep commented Jan 18, 2024

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

@andrewbess
Copy link

Hello @hostep
Thank you for your contribution
Looks like the failed tests are not related on your changes

Copy link

@andrewbess andrewbess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fixes look nice for me
Approved

@andrewbess
Copy link

@magento run Functional Tests B2B, WebAPI 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.

@ihor-sviziev ihor-sviziev added Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Award: category of expertise labels Jan 19, 2024
@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 Jan 30, 2024
@hostep
Copy link
Contributor Author

hostep commented Feb 1, 2024

I don't see why that DevExperience label was added? Because this will cause issues on production environments once the ICU library used by PHP is at the latest version...

@sinhaparul sinhaparul added the Project: Community Picked PRs upvoted by the community label Mar 4, 2024
@engcom-Echo
Copy link
Contributor

@magento run all tests

@engcom-Echo
Copy link
Contributor

✔️ QA Passed

Preconditions:

  • Install fresh Magento 2.4-develop

Manual testing scenario:
We have followed steps from comment

Before: ✖️ 
Screenshot 2024-03-07 at 1 17 20 PM

After: ✔️  
Screenshot 2024-03-07 at 1 30 49 PM

Builds are failed. Hence, moving this PR to Extended Testing.

@engcom-Echo
Copy link
Contributor

@magento run all tests

@engcom-Echo
Copy link
Contributor

@magento run WebAPI Tests,Unit Tests,Functional Tests EE,Functional Tests CE,Functional Tests B2B,Integration Tests

@engcom-Echo
Copy link
Contributor

@magento run Functional Tests EE,Functional Tests CE,Functional Tests B2B

@engcom-Echo
Copy link
Contributor

@magento run Unit Tests,Integration Tests

@engcom-Echo
Copy link
Contributor

WebAPI Tests failure are known failure not related to PR changes.
Functional Tests EE,Functional Tests B2B failure are different on last two run on same commit.
Functional Tests EE
Run1
Screenshot 2024-03-11 at 3 43 46 PM

Run2
Screenshot 2024-03-11 at 3 45 02 PM

Functional Tests B2B
Run1
Screenshot 2024-03-11 at 3 43 10 PM

Run2
Screenshot 2024-03-11 at 3 43 17 PM

Hence moving to merge in progress

@magento-devops-reposync-svc magento-devops-reposync-svc merged commit 18ffc1d into magento:2.4-develop May 16, 2024
9 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Award: category of expertise Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. 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
Status: Recently Merged
Development

Successfully merging this pull request may close these issues.

Exception: Warning: Trying to access array offset in... -> Calendar.php since upgrade to ICU 74.1 (PHP Intl)
7 participants