Skip to content

Fix issue with di.xml config merging for classes array argument in case of different sources and the class name difference in leading slash. #20891

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

Conversation

swnsma
Copy link
Contributor

@swnsma swnsma commented Feb 2, 2019

Description

PR to fix the reasons of #20410 (issue #20409).
During research I have discovered bug in config merging from di.xml.
Merging of nested arguments (array) in case of difference in class name (leading slash) in different files can leads to config lost.

Fixed Issues (if relevant)

  1. Magento\Catalog\Api\ProductRenderListInterface returns products regardless of visibility #20409
  2. Types not merged for etc/di.xml etc/adminhtml/di.xml #21193

Manual testing scenarios

Pre-Conditions

  1. Change constructor of \Magento\Cms\Controller\Index\Index and add new argument 'data' (simple way to visualize it):
public function __construct(`
`        Context $context,`
        ForwardFactory $resultForwardFactory,
        ScopeConfigInterface $scopeConfig = null,
        Page $page = null,
        array $data = []
    ) {
        var_dump($data);
        die;
    }

Steps to reproduce

  1. Create module A and B with simple config set (registration.php and module.xml).
  2. Execute in terminal php bin/magento setup:upgrade.
  3. Create etc/di.xml for module A:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Cms\Controller\Index\Index">
        <arguments>
            <argument name="data" xsi:type="array">
                <item name="p1" xsi:type="string">Hello Phrase1</item>
            </argument>
        </arguments>
    </type>
</config>
  1. Create etc/di.xml for module B:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="\Magento\Cms\Controller\Index\Index">
        <arguments>
            <argument name="data" xsi:type="array">
                <item name="p2" xsi:type="string">Hello Phrase2</item>
            </argument>
        </arguments>
    </type>
</config>
  1. Execute in terminal php bin/magento cache:flush
  2. Open home page.

Expected results

image

Actual results

image

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

…array argument in case of different sources and the class name difference in leading slash.
@magento-engcom-team
Copy link
Contributor

Hi @swnsma. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

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

@magento-engcom-team magento-engcom-team added Component: Framework/ObjectManager Release Line: 2.3 Partner: ISM eCompany Pull Request is created by partner ISM eCompany partners-contribution Pull Request is created by Magento Partner labels Feb 2, 2019
@dominicfernando
Copy link

dominicfernando commented Feb 3, 2019

@swnsma

\ making the problem. But I think you try to solve \ problem.

<type name="\Magento\Cms\Controller\Index\Index"> <arguments> <argument name="data" xsi:type="array"> <item name="p2" xsi:type="string">Hello Phrase2</item> </argument> </arguments> </type>

@magento-engcom-team
Copy link
Contributor

Hi @sivaschenko, thank you for the review.
ENGCOM-4094 has been created to process this Pull Request

@swnsma
Copy link
Contributor Author

swnsma commented Feb 3, 2019

@dominicfernando
Yes.
There only difference for now is during array arguments merge :)

@Nazar65
Copy link
Member

Nazar65 commented Feb 19, 2019

HI @swnsma your PR also fixes this issue -> #21193 your changes solves this

@swnsma
Copy link
Contributor Author

swnsma commented Feb 20, 2019

Hi @Nazar65,
Thanks!

@nmalevanec nmalevanec changed the title magento/magento2#?: fix issue with di.xml config merging for classes array argument in case of different sources and the class name difference in leading slash. Fix issue with di.xml config merging for classes array argument in case of different sources and the class name difference in leading slash. Feb 21, 2019
@p-bystritsky p-bystritsky self-assigned this Mar 6, 2019
@swnsma swnsma closed this Mar 15, 2019
@ghost
Copy link

ghost commented Mar 15, 2019

Hi @swnsma, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@swnsma
Copy link
Contributor Author

swnsma commented Mar 16, 2019

PR break Backward Compatibility due to merging of configs between general and concrete application level (e.g. adminhtml/frontend) leads to merging of configs (after changes in this PR) but not replacing of configs (before changes in this PR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: ObjectManager Partner: ISM eCompany Pull Request is created by partner ISM eCompany partners-contribution Pull Request is created by Magento Partner Release Line: 2.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants