magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Array offset error in framework/View/Element/Html/Calendar.php

Open n2diving-dgx opened this issue 3 years ago • 7 comments

Following an upgrade of M2.3.6-p1/php7.3 to M2.3.7/php7.4 an error similar to...

main.CRITICAL: Notice: Trying to access array offset on value of type null in /vendor/magento/framework/View/Element/Html/Calendar.php on line 112

appears in the var/log/system.log each time the crontab runs, i.e. a few times per minute. The cause is a compatibility issue with Calendar.php that was identified and addressed in M2.4.0-beta... see the lengthy discussion in https://github.com/magento/magento2/issues/28729

Apparently the fix to Calendar.php was applied to M2.4.0 release, but the fix was not backported to M2.3.7 when the requirement for updating to php7.4 was mandated (which indirectly triggered an update to the offending version of the library). Here is a .diff of essentially the M2.4.0 patch for the M2.3.7 version of Calendar, which resolved the problem in my M2.3.7 production environment.

--- a/View/Element/Html/Calendar.php
+++ b/View/Element/Html/Calendar.php
@@ -108,9 +108,7 @@
             ]
         );
 
-        // get "today" and "week" words
-        $this->assign('today', $this->encoder->encode($localeData['fields']['day']['relative']['0']));
-        $this->assign('week', $this->encoder->encode($localeData['fields']['week']['dn']));
+        $this->assignFieldsValues($localeData);
 
         // get "am" & "pm" words
         $this->assign('am', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkers']['0']));
@@ -190,4 +188,25 @@
         return (new \DateTime())->modify('- 100 years')->format('Y')
             . ':' . (new \DateTime())->modify('+ 100 years')->format('Y');
     }
+
+    /**
+     * Assign "fields" values from the ICU data
+     *
+     * @param \ResourceBundle $localeData
+     */
+    private function assignFieldsValues(\ResourceBundle $localeData): void
+    {
+        /**
+         * Fields value in the current position has been added to ICU Data tables
+         * starting with ICU library version 51.1.
+         * Due to fact that we do not use these variables in templates, we do not initialize them for older versions
+         *
+         * @see https://github.com/unicode-org/icu/blob/release-50-2/icu4c/source/data/locales/en.txt
+         * @see https://github.com/unicode-org/icu/blob/release-51-2/icu4c/source/data/locales/en.txt
+         */
+        if ($localeData->get('fields')) {
+            $this->assign('today', $this->encoder->encode($localeData['fields']['day']['relative']['0']));
+            $this->assign('week', $this->encoder->encode($localeData['fields']['week']['dn']));
+        }
+    }
 }

n2diving-dgx avatar May 13 '21 15:05 n2diving-dgx

Hi @n2diving-dgx. Thank you for your report. To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

Please, add a comment to assign the issue: @magento I am working on this


:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

m2-assistant[bot] avatar May 13 '21 15:05 m2-assistant[bot]

Hi @mrtuvn. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar May 14 '21 23:05 m2-assistant[bot]

cc: @gabrieldagama @sivaschenko maybe this commit fix related issue (https://github.com/magento/magento2/commit/c4ca054a7dbf1454a32bb256314958bac1ebd952) not sync to 2.3.7

mrtuvn avatar May 14 '21 23:05 mrtuvn

@sivaschenko @sidolov @gabrieldagama, please add porting of https://github.com/magento/magento2/commit/c4ca054a7dbf1454a32bb256314958bac1ebd952 to the 2.3 release line.

ihor-sviziev avatar May 24 '21 08:05 ihor-sviziev

Was this ever fixed in the 2.3 release line?

luccame avatar Feb 15 '22 03:02 luccame

Hi @engcom-Alfa. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Jul 26 '22 09:07 m2-assistant[bot]

Hello @n2diving-dgx,

We have moved this ticket to on hold for the PO confirmation.

Thanks

engcom-Hotel avatar Aug 09 '22 07:08 engcom-Hotel

Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Dec 13 '22 10:12 m2-assistant[bot]

Hello @n2diving-dgx,

We have received a reply from the PO, actually, we do not release any fixes for 2.3 release line, but if the community wants they could potentially release a hotfix for the 2.3.x release line by themselves by using the QPT tool:

https://github.com/magento/quality-patches

Thanks

engcom-Hotel avatar Mar 29 '23 07:03 engcom-Hotel