-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
[Config] Array to string conversion error when saving row system config with defaults #30314
Comments
Hi @Naitsirch. Thank you for your report.
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:
For more details, please, review the Magento Contributor Assistant documentation. Please, add a comment to assign the issue:
🕙 You can find the schedule on the Magento Community Calendar page. 📞 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. 🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
@magento I am working on this |
@magento I am working on this |
Hi @wagento-rajan! 👋 |
…th defaults This PR solves issue magento#30314. The backend model that is designed to handle complex values serializes non-scalar values before they are persisted to database. But when the old value is loaded from config defaults (defined in config.xml) for comparison, the default value is fetched as array. When the array is casted to string it results in an array to string conversion error. This issue is fixed by serializing the default value coming from the config.
@wagento-rajan I have already created a PR for this issue ;-) |
Hi @engcom-Alfa. Thank you for working on this issue.
|
The issue is reproducible on fresh 2.4-develop. Manual testing scenario:
<default>
<general>
<quantity_ranges>
<ranges>
<item1>
<from_qty>1</from_qty>
<to_qty>5</to_qty>
<price>10.00</price>
<tax>1</tax>
</item1>
<item2>
<from_qty>6</from_qty>
<to_qty>10</to_qty>
<price>20.00</price>
<tax>1</tax>
</item2>
<item3>
<from_qty>11</from_qty>
<to_qty>15</to_qty>
<price>30.00</price>
<tax>0</tax>
</item3>
</ranges>
</quantity_ranges>
</general>
</default> 3. Actual Result: ✖️ got the following error: |
✅ Confirmed by @engcom-Alfa Issue Available: @engcom-Alfa, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself. |
Hi @Naitsirch. Thank you for your report. The fix will be available with the upcoming 2.4.2 release. |
Can you merge this PR in Magento 2.4.1 version also? |
If someone get this error and need a quick fix (without updating the Magento version or adding a patch) you can just add an serialized array on the config.xml file as the default field value. As Magento get the default info from XML as an array and does not have the format convertion you can just pass already as a serialized value. Example:
Passing the value already as serialized the Magento getOldValue function doesn't need the conversion. The default values appear normally on the painel with the error fixed. |
Preconditions (*)
I am using Magento 2.4.0 in development mode with PHP 7.4.10 on Linux, Debian Buster.
Also verified and confirmed on
2.4-develop
open source editionSteps to reproduce (*)
We followed these instructions to create a dynamic row system config.
We have added default values to my
etc/config.xml
in this form:3.
Go to Admin -> System -> Configuration -> Quantity Ranges
and click on the Save Config buttonExpected result (*)
Save the configs.
Actual result (*)
I get the following error:
When I remove the defaults from the config.xml and clear the cache, the saving works correctly.
Notice
I have tried to debug the issue. What I found out so long is that Magento serializes the data in the config value to json in
Magento\Config\Model\Config\Backend\Serialized::beforeSave
and saves it in the data array.In
Magento\Framework\App\Config\Value::afterSave
it calls$this->isValueChanged()
where it compares$this->getValue() != $this->getOldValue()
. Now ingetOldValue
it uses the default value coming from the XML config which is stored as array and is not serialized. At the point where the array is tried to be casted to a string, the error occures.The text was updated successfully, but these errors were encountered: