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

[Config] Array to string conversion error when saving row system config with defaults #30314

Closed
1 of 5 tasks
stollr opened this issue Oct 2, 2020 · 11 comments · Fixed by #30322
Closed
1 of 5 tasks

[Config] Array to string conversion error when saving row system config with defaults #30314

stollr opened this issue Oct 2, 2020 · 11 comments · Fixed by #30322
Assignees
Labels
Component: Config Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Priority: P3 May be fixed according to the position in the backlog. Progress: done Reported on 2.4.0 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.

Comments

@stollr
Copy link
Contributor

stollr commented Oct 2, 2020

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 edition

Steps to reproduce (*)

  1. We followed these instructions to create a dynamic row system config.

  2. We have added default values to my etc/config.xml in this form:

     <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. Go to Admin -> System -> Configuration -> Quantity Ranges and click on the Save Config button

Expected result (*)

Save the configs.

Actual result (*)

I get the following error:

Notice: Array to string conversion in /path/to/magento/vendor/magento/framework/App/Config/Value.php on line 100

2020-10-20_16-42

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 in getOldValue 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.


  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
@m2-assistant
Copy link

m2-assistant bot commented Oct 2, 2020

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


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

🕙 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

@stollr
Copy link
Contributor Author

stollr commented Oct 2, 2020

@magento I am working on this

@wagento-rajan
Copy link

@magento I am working on this

@m2-assistant
Copy link

m2-assistant bot commented Oct 2, 2020

Hi @wagento-rajan! 👋
Thank you for collaboration. Only members of Community Contributors Team are allowed to be assigned to the issue. Please use @magento add to contributors team command to join Contributors team.

stollr added a commit to stollr/magento2 that referenced this issue Oct 2, 2020
…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.
@stollr
Copy link
Contributor Author

stollr commented Oct 2, 2020

@wagento-rajan I have already created a PR for this issue ;-)

@engcom-Alfa engcom-Alfa self-assigned this Oct 20, 2020
@m2-assistant
Copy link

m2-assistant bot commented Oct 20, 2020

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: 👇

  • 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-community-project m2-community-project bot moved this from Dev In Progress to Pull Request In Progress in Low Priority Backlog Oct 20, 2020
@m2-community-project m2-community-project bot added Progress: PR Created Indicates that Pull Request has been created to fix issue and removed Progress: dev in progress Progress: PR Created Indicates that Pull Request has been created to fix issue labels Oct 20, 2020
@engcom-Alfa
Copy link
Contributor

The issue is reproducible on fresh 2.4-develop.

Manual testing scenario:

  1. We followed these instructions to create a dynamic row system config.

  2. We have added default values to my etc/config.xml in this form:

     <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. Go to Admin -> System -> Configuration -> Quantity Ranges and click on the Save Config button

Actual Result: ✖️ got the following error:

2020-10-20_16-42

@sidolov sidolov added the Priority: P3 May be fixed according to the position in the backlog. label Oct 20, 2020
@ghost ghost added Progress: PR in progress and removed Progress: PR Created Indicates that Pull Request has been created to fix issue labels Oct 20, 2020
@engcom-Alfa engcom-Alfa added Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Component: Config Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Oct 21, 2020
@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Oct 21, 2020
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Alfa
Thank you for verifying the issue. Based on the provided information internal tickets MC-38588 were created

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.

@ghost ghost moved this from Pull Request In Progress to Ready for Development in Low Priority Backlog Oct 21, 2020
@ghost ghost moved this from Pull Request In Progress to Ready for Development in Low Priority Backlog Oct 21, 2020
@magento-engcom-team
Copy link
Contributor

Hi @Naitsirch. Thank you for your report.
The issue has been fixed in #30322 by @Naitsirch in 2.4-develop branch
Related commit(s):

The fix will be available with the upcoming 2.4.2 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.4.x The issue has been fixed in 2.4-develop branch label Oct 24, 2020
@ghost ghost moved this from Ready for Development to Done in Low Priority Backlog Oct 24, 2020
@ghost ghost moved this from Done to Pull Request In Progress in Low Priority Backlog Oct 24, 2020
@sdzhepa sdzhepa added the Reported on 2.4.0 Indicates original Magento version for the Issue report. label Nov 11, 2020
@m2-community-project m2-community-project bot moved this from Pull Request In Progress to Done in Low Priority Backlog Nov 11, 2020
@eikoncode
Copy link

Can you merge this PR in Magento 2.4.1 version also?

@CUTTRHOAT69
Copy link

CUTTRHOAT69 commented Aug 18, 2022

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:

<default>
    <general>
        <quantity_ranges>
            <ranges>
            {
                "item1":{"from_qty":"1","to_qty":"5","price":"10.00","tax":"1"},
                "item2":{"from_qty":"6","to_qty":"0","price":"20.00","tax":"1"},
                "item3":{"from_qty":"11","to_qty":"15","price":"30.00","tax":"0"}
            }
            </ranges>
        </quantity_ranges>
    </general>
</default>

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.
It's just works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Config Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Priority: P3 May be fixed according to the position in the backlog. Progress: done Reported on 2.4.0 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
Development

Successfully merging a pull request may close this issue.

8 participants