magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.47k stars 9.28k forks source link

M 2.4.0 upgrading issue - Unable to apply patch Magento\Review\Setup\Patch\Schema\AddUniqueConstraintToReviewEntitySummary #29352

Closed jesperbrejning closed 4 years ago

jesperbrejning commented 4 years ago

Preconditions

Install Magento 2.3.5 CE using composer

Steps to reproduce

  1. Run SQL command
    
    INSERT INTO review*entity*summary 
    (`entity*pk_value`, `entity_type`, `reviews_count`, `rating_summary`, `store*id`) 
    VALUES (1, 1, 1, 1, 1),(1, 1, 1, 2, 1);
    {code}
  2. Follow a general upgrade flow <https://devdocs.magento.com/guides/v2.4/comp-mgr/cli/cli-upgrade.html] and upgrade to 2.4.0

() Upgrade completed successfully (-) {code:bash} Unable to apply patch Magento\Review\Setup\Patch\Schema\AddUniqueConstraintToReviewEntitySummary for module MagentoReview. Original exception message: Warning: pregmatch(): Compilation failed: invalid range in character class at offset 40 in /Users/max/srv/composer/m2ee.composer/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php on line 2779 {code} Overview:

When upgrading from 2.3.5 to 2.4.0 and running php bin/magento setup:upgrade, the following error appears:

Unable to apply patch Magento\Review\Setup\Patch\Schema\AddUniqueConstraintToReviewEntitySummary for module Magento_Review. Original exception message: Warning: preg_match(): Compilation failed: invalid range in character class at offset 40 in /home/babygear/www/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php on line 2779

This issue is caused by a regular expression used in Magento code, which is not compatible with PHP 7.3 and PHP 7.4 

{code:bash}

SQLSTATE[23000]: [:]: 1062[\']\'([\d-.])\'



 

Please find more details here [https://github.com/magento/magento2/issues/29352>

 
m2-assistant[bot] commented 4 years ago

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

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


: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

hostep commented 4 years ago

Hmm, that's interesting, the regex you refer to is #SQLSTATE\[23000\]: [^:]+: 1062[^\']+\'([\d-\.]+)\'#

I think you have a point here, the problem is inside the [\d-\.] character class, the range character - is considered a true range character because it wasn't specified as the last character in the group, so the solution is most likely to change the regex from:

#SQLSTATE\[23000\]: [^:]+: 1062[^\']+\'([\d-\.]+)\'#

to:

#SQLSTATE\[23000\]: [^:]+: 1062[^\']+\'([\d\-\.]+)\'#

or:

#SQLSTATE\[23000\]: [^:]+: 1062[^\']+\'([\d\.-]+)\'#

Could you test both these suggested regexes and let me know which ones fixes your issue?

For completeness sake, can you specify the PHP version and the version of the pcre library you are using. You can find these on the command line using:

php --version
php -i | grep PCRE

Thanks!

hostep commented 4 years ago

I can very easily reproduce the problem using PHP 7.3 and 7.4 (it works on PHP 7.2) with:

$ php -r "preg_match('#SQLSTATE\[23000\]: [^:]+: 1062[^\']+\'([\d-\.]+)\'#', 'whatever');"
PHP Warning:  preg_match(): Compilation failed: invalid range in character class at offset 40 in Command line code on line 1

Warning: preg_match(): Compilation failed: invalid range in character class at offset 40 in Command line code on line 1

I'm using:

PCRE Library Version => 10.35 2020-05-09
PCRE Unicode Version => 13.0.0

This most likely happens because PHP 7.3 and 7.4 upgraded from the pcre library version 1 to version 2 and the last one is probably more stricter: https://php.watch/versions/7.3#pcre2

Thanks for the bug report, it's truly an important bug and hopefully somebody will fix this shortly (and search the entire codebase for other possible variants of this bug and also fix those)

martysmojo commented 4 years ago

Can confirm I see this bug with a 2.4. upgrade

$ php -i | grep PCRE PCRE (Perl Compatible Regular Expressions) Support => enabled PCRE Library Version => 10.32 2018-09-10 PCRE Unicode Version => 11.0.0 PCRE JIT Support => enabled PCRE JIT Target => x86 64bit (little endian + unaligned)

$ php --version PHP 7.3.20 (cli) (built: Jul 22 2020 09:57:21) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.20, Copyright (c) 1998-2018 Zend Technologies with the ionCube PHP Loader + ionCube24 v10.4.1, Copyright (c) 2002-2020, by ionCube Ltd. with SourceGuardian v11.4.1, Copyright (c) 2000-2020, by SourceGuardian Ltd. with Zend OPcache v7.3.20, Copyright (c) 1999-2018, by Zend Technologies

martysmojo commented 4 years ago

To amend my other comment, I couldn't replicate this using vanilla Magento installs from 2.3.4 to 2.4.0 (the above case was 2.3.4 to 2.4.0) so its not clear why its failing to update in our case.

fascinosum commented 4 years ago

Hello @jesperbrejning, @hostep, @martysmojo thank you for your contribution. An internal ticket has been created to track this issue MC-36428 @martysmojo this issue can be reproduced using a specific data set

magento-engcom-team commented 4 years ago

Hi @jesperbrejning.

Thank you for your report and collaboration!

The issue was fixed by Magento team. The fix was delivered into magento/magento2:2.4-develop branch(es). Related commit(s):

The fix will be available with the upcoming 2.4.1 release.