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.46k stars 9.28k forks source link

Error Deprecated Functionality plugin magento zendframework1 #36069

Open mohammedTBB opened 2 years ago

mohammedTBB commented 2 years ago

Preconditions and environment

Steps to reproduce

1- Go to category page 2- Choose a product and go to product page (not all products)

Expected result

No error

Actual result

Exception #0 (Exception): Deprecated Functionality: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /vendor/magento/zendframework1/library/Zend/Db/Statement.php on line 222

#1 call_user_func_array() called at [app/code/Anowave/Ec/vendor/FacebookAds/CrashReporter.php:154]
#2 Anowave\Ec\vendor\FacebookAds\CrashReporter->Anowave\Ec\vendor\FacebookAds\{closure}()
#3 preg_replace() called at [vendor/magento/zendframework1/library/Zend/Db/Statement.php:222]
#4 Zend_Db_Statement->_stripQuoted() called at [vendor/magento/zendframework1/library/Zend/Db/Statement.php:139]
#5 Zend_Db_Statement->_parseParameters() called at [vendor/magento/zendframework1/library/Zend/Db/Statement.php:114]
#6 Zend_Db_Statement->__construct() called at [vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php:184]
#7 Zend_Db_Adapter_Pdo_Abstract->prepare() called at [vendor/magento/zendframework1/library/Zend/Db/Adapter/Abstract.php:479]
#8 Zend_Db_Adapter_Abstract->query() called at [vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php:238]
#9 Zend_Db_Adapter_Pdo_Abstract->query() called at [vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:564]
#10 Magento\Framework\DB\Adapter\Pdo\Mysql->_query() called at [vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:634]
#11 Magento\Framework\DB\Adapter\Pdo\Mysql->query() called at [vendor/magento/zendframework1/library/Zend/Db/Adapter/Abstract.php:737]
#12 Zend_Db_Adapter_Abstract->fetchAll() called at [vendor/magento/framework/Data/Collection/Db/FetchStrategy/Query.php:21]
#13 Magento\Framework\Data\Collection\Db\FetchStrategy\Query->fetchAll() called at [vendor/magento/framework/Data/Collection/AbstractDb.php:782]
#14 Magento\Framework\Data\Collection\AbstractDb->_fetchAll() called at [vendor/magento/framework/Data/Collection/AbstractDb.php:677]
#15 Magento\Framework\Data\Collection\AbstractDb->getData() called at [vendor/magento/framework/Data/Collection/AbstractDb.php:580]
#16 Magento\Framework\Data\Collection\AbstractDb->loadWithFilter() called at [vendor/magento/framework/Data/Collection/AbstractDb.php:565]
#17 Magento\Framework\Data\Collection\AbstractDb->load() called at [vendor/magento/module-eav/Model/Entity/Attribute/Source/Table.php:123]
#18 Magento\Eav\Model\Entity\Attribute\Source\Table->getSpecificOptions() called at [vendor/magento/module-eav/Model/Entity/Attribute/Source/Table.php:157]
#19 Magento\Eav\Model\Entity\Attribute\Source\Table->getOptionText() called at [vendor/magento/module-catalog/Model/Product.php:1807]
#20 Magento\Catalog\Model\Product->getAttributeText() called at [vendor/amasty/module-google-rich-snippets/Block/Product.php:427]
#21 Amasty\SeoRichData\Block\Product->updateCustomProperties() called at [vendor/amasty/module-google-rich-snippets/Block/Product.php:327]
#22 Amasty\SeoRichData\Block\Product->generateOffers() called at [vendor/amasty/module-google-rich-snippets/Block/Product.php:210]
#23 Amasty\SeoRichData\Block\Product->prepareOffers() called at [vendor/amasty/module-google-rich-snippets/Block/Product.php:150]
#24 Amasty\SeoRichData\Block\Product->getResultArray() called at [vendor/amasty/module-google-rich-snippets/Block/Product.php:133]
#25 Amasty\SeoRichData\Block\Product->_toHtml() called at [vendor/magento/framework/View/Element/AbstractBlock.php:1095]
#26 Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}() called at [vendor/magento/framework/View/Element/AbstractBlock.php:1099]
#27 Magento\Framework\View\Element\AbstractBlock->_loadCache() called at [vendor/magento/framework/View/Element/AbstractBlock.php:660]
#28 Magento\Framework\View\Element\AbstractBlock->toHtml() called at [vendor/magento/framework/View/Layout.php:578]
#29 Magento\Framework\View\Layout->_renderBlock() called at [vendor/magento/framework/View/Layout.php:555]
#30 Magento\Framework\View\Layout->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510]
#31 Magento\Framework\View\Layout->renderElement() called at [vendor/magento/framework/View/Layout.php:606]
#32 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557]
#33 Magento\Framework\View\Layout->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510]
#34 Magento\Framework\View\Layout->renderElement() called at [vendor/magento/framework/View/Layout.php:606]
#35 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557]
#36 Magento\Framework\View\Layout->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510]
#37 Magento\Framework\View\Layout->renderElement() called at [vendor/magento/framework/View/Layout.php:606]
#38 Magento\Framework\View\Layout->_renderContainer() called at [vendor/magento/framework/View/Layout.php:557]
#39 Magento\Framework\View\Layout->renderNonCachedElement() called at [vendor/magento/framework/View/Layout.php:510]
#40 Magento\Framework\View\Layout->renderElement() called at [vendor/magento/framework/View/Layout.php:975]
#41 Magento\Framework\View\Layout->getOutput() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#42 Magento\Framework\View\Layout\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#43 Magento\Framework\View\Layout\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#44 Magento\Framework\View\Layout\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:41]
#45 Magento\Framework\View\Layout\Interceptor->getOutput() called at [vendor/magento/framework/View/Result/Page.php:260]
#46 Magento\Framework\View\Result\Page->render() called at [vendor/magento/framework/View/Result/Layout.php:171]
#47 Magento\Framework\View\Result\Layout->renderResult() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#48 Magento\Framework\View\Result\Page\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#49 Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#50 Magento\Framework\View\Result\Page\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/View/Result/Page/Interceptor.php:32]
#51 Magento\Framework\View\Result\Page\Interceptor->renderResult() called at [vendor/magento/framework/App/Http.php:120]
#52 Magento\Framework\App\Http->launch() called at [vendor/magento/framework/App/Bootstrap.php:264]
#53 Magento\Framework\App\Bootstrap->run() called at [pub/index.php:30]

Additional information

Possible solution:

diff --git a/vendor/magento/zendframework1/library/Zend/Db/Statement.php b/vendor/magento/zendframework1/library/Zend/Db/Statement.php
index 46d175c..60c77a9 100644
--- a/vendor/magento/zendframework1/library/Zend/Db/Statement.php
+++ b/vendor/magento/zendframework1/library/Zend/Db/Statement.php
@@ -209,6 +209,10 @@ abstract class Zend_Db_Statement implements Zend_Db_Statement_Interface
         // remove "foo\"bar"
         $sql = preg_replace("/\"(\\\\\"|[^\"])*\"/Us", '', $sql);

+        if ($sql === null) {
+            return '';
+        }
+
         // get the character for delimited id quotes,
         // this is usually " but in MySQL is `
         $d = $this->_adapter->quoteIdentifier('a');

Need to add this check after each preg_replace call i.e. 210 & 222. The simplest way to reproduce this issue is by setting $sql as null and then running bin/magento setup:upgrade command. The below error will occur: image

Release note

No response

Triage and priority

m2-assistant[bot] commented 2 years ago

Hi @mohammedTBB. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

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

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


: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, join the Community Contributions Triage session to discuss the appropriate ticket.

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

m2-assistant[bot] commented 2 years ago

Hi @engcom-Dash. 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:


engcom-Dash commented 2 years ago

Hi @mohammedTBB ,

We are trying to reproduce the issue in 2.4.5 magento instance....But we are not able to reproduce the issue. We are getting expected result and it is not reproducible.

Steps: 1.install 2.4.5 magento instance 2.Go to category page 3.Select the product 4.got to product page 5.No error occurring

Let us know if we missing anything!

Thanks!!!

n2diving-dgx commented 2 years ago

Maybe the Anowave E-commerce 3rd party package script (i.e. CrashReporter.php) detects an issue that triggers a call to Zend/DbStatement.php... which in turn then executes the deprecated functionality in M2 zendframework? Perhaps wouldn't be reproduceable unless Anowave EC extension tries to report the "crash". We've had a several of that kind of circumstance in debugging php8.1 compatibility issues in 3rd party extensions: fix the first bit of deprecated code, test and that reveals a new one downstream... rinse and repeat.

image

m2-assistant[bot] commented 2 years ago

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:

engcom-Hotel commented 2 years ago

Hello @mohammedTBB,

Thanks for the report and collaboration!

We have checked this issue in the Magento 2.4.5, 2.4.4, and 2.4-develop branches. And also examine the file vendor/magento/zendframework1/library/Zend/Db/Statement.php and found that the suggested possible fix as below:

if ($sql === null) {
           return '';
}

is already there in line no. 201.

https://github.com/magento/zf1/blob/2381396d2a9a528be2f367b5ce2dddf650eac1d0/library/Zend/Db/Statement.php#L201

Hello @n2diving-dgx,

Can you please suggest a way to reproduce the issue? Does we need to install the Anowave E-commerce, and the try to throw an issue. Please suggest.

Thanks

hostep commented 2 years ago

@engcom-Hotel: if you read the error message carefully, you'll see that the error happens on line 222. Which means that the check on line 201 already passed.

So this most likely means that the second preg_replace call failed, which would explain why the $sql value changes to null.

Also, we have a third preg_replace call, which could potentially also fail, so maybe that one needs to be checked as well?

mohammedTBB commented 2 years ago

Hello @engcom-Hotel

yes there is check in line 201 but then the value of $sql changed.

what worked for us is adding the check at line 222

image

to reproduce the error it is essential to have the plugin amasty google rich snippets, knowing that disabling this plugin the error is no longer showing.

what seems to happen that the plugin amasty google rich snippets calls a zendfremwork funcion where the error happen.

engcom-Hotel commented 2 years ago

Hello @hostep @mohammedTBB,

Thanks for the reply!

I agree with your point @hostep, we need to add the checks after each preg_replace call here ie. line numbers i.e. 210 & 222.

I have also gone through the preg_replace documentation, it can be returned as null, in case of error occurred.

Hence confirming the issue.

Thanks

github-jira-sync-bot commented 2 years ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-6632 is successfully created for this GitHub issue.

m2-assistant[bot] commented 2 years ago

:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

Aquive commented 1 year ago

@mohammedTBB @hostep @n2diving-dgx does anyone of you know how to reproduce this issue? From what I can read, it does not always occur? I have the same situation for a client.

hostep commented 1 year ago

@Aquive: try outputting/debugging what the $sql variable contains just before this and this line. That might reveal why preg_replace runs into an error in your case.

Feel free to report back here, it will most likely make it easier to understand for the people involved here how it can happen.

Aquive commented 1 year ago

@hostep the error sometimes occurs on production. But the problem for me is that I don't know how to reproduce this locally.

Any ideas?

hostep commented 1 year ago

The only thing I can think of, is to patch the code on production with some extra lines that try to detect this occurrence and add a bunch of logging to try to see what the $sql variable contains just before it turns into null... And then hope that after a few days you'll find something interesting in your log files which can then hopefully explain what's going on.

joshbourke commented 1 year ago

I stumbled across this recently. If you go to the Customer Grid in the admin and search: ':{}{}{":]a''a'a':{}{}{"a:]{":a'a':{}{}{":]a'']a''a'a':{}{}:]{":a'a':{}{}{":]a'']a''a'a':{}{}:]{":a'a':{}{}{":]a:]{":a'a':{}{}{":]a'']a''a'a':{}{}:]{":a'a':{}{:]{":a'a':{}{}{":]a'']a''a'a':{}{}:]{":a'a':]{":a'a':{}{}{":]a'']a''a'a':{}{}:]{"::]{":a'a':{}{}{":]a'']a''a'a':{}{}a'a':{}{}{":]a'']a''a'a':{}{}:{}{}{":]a'']a''a'a':{}{}}{":]a'']a''a'a':{}{}'']a''a'a':{}{}{"a:]a''a'a':{}':{}{}{":]a''a'a':{}{}{"a:]a''a'a':{}':{}{}{":]a''a'a':{}{}{"a:]a''a'a':{}':{}{}{":]a''a'a':{}{}{"a:]a''a'a':{}':{}{}{":]a''a'a':{}{}{"a:]a''a'a':{}':{}{}{":]a''a'a':{}{}{"a:]a''a'a':{}':{}{}{":]a''a'a':{}{}{"a:]a''a'a':{}':':

You create an exception that stems from the same problem.

Note that you may hit a server error if the request URI is too long. You may need to adjust server config.

You have to be in production mode or have error reporting off because of a check done here: vendor/magento/framework/App/ErrorHandler.php:54

        $errorNo = $errorNo & error_reporting();
        if ($errorNo == 0) {
            return false;
        }

Exception:

[2023-01-18T19:42:07.045616+00:00] report.CRITICAL: Exception: Deprecated Functionality: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /chroot/home/website/html/vendor/magento/zendframework1/library/Zend/Db/Statement.php on line 222 in /chroot/home/website/html/vendor/magento/framework/App/ErrorHandler.php:62
Stack trace:
#0 [internal function]: Magento\Framework\App\ErrorHandler->handler(8192, 'preg_replace():...', '/chroot/home/mt...', 222)
cptX commented 1 year ago

I hit the same issue but on a different case. I have magento 2.4.5. When trying to rollback my database I got this: Deprecated Functionality: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/xxxxxxx/vendor/magento/zendframework1/library/Zend/Db/Statement.php on line 222

This breaks the rollback of the database so I think is critical. At the moment I cannot restore my database! Any suggestions?