magento2
magento2 copied to clipboard
Bug in DI generation: array arguments got replaced instead of merging when modified from different area
Preconditions (*)
- Create a configurable object or virtual type e.g. composite
- It's impossible to add new items into array argument for different area.
- Related problem was reported here: https://stackoverflow.com/questions/34635615/magento-2-how-to-add-new-value-to-the-array-on-di-xml
Other should areas extend di configuration from global, or override only changed items/arguments. But in case with array arguments the DI compilation process overrides entire array instead of merging its items.
See the code in methods:
\Magento\Framework\ObjectManager\Config\Config::_mergeConfiguration L248
\Magento\Framework\ObjectManager\Config\Config::_collectConfiguration L210
the arguments will be replaced

Steps to reproduce (*)
- Configure an object in global area
GLOBAL area di.xml
<virtualType name="SomeCompositeHandler" type="Magento\Payment\Gateway\Response\HandlerChain">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="some_handler_global" xsi:type="string">SomeHandlerGlobal</item>
</argument>
</arguments>
</virtualType>
- Modify the object in adminhtml area
ADMINHTML area di.xml
<virtualType name="SomeCompositeHandler">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="some_handler_for_admin" xsi:type="string">SomeHandlerForAdmin</item>
</argument>
</arguments>
</virtualType>
Expected result (*)
- The final object in code contains handlers from both areas as if it was defined like this in di.xml
Expected result for ADMINHTML area:
<virtualType name="SomeCompositeHandler">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="some_handler_global" xsi:type="string">SomeHandlerGlobal</item>
<item name="some_handler_for_admin" xsi:type="string">SomeHandlerForAdmin</item>
</argument>
</arguments>
</virtualType>
Actual result (*)
- The
handlersarray argument got overridden instead of merged and works only the way defined in admin.
Actual result for ADMINHTML area:
<virtualType name="SomeCompositeHandler">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="some_handler_for_admin" xsi:type="string">SomeHandlerForAdmin</item>
</argument>
</arguments>
</virtualType>
So global handler is lost.
WORKAROUND:
Add all missed arguments from global area if you want to add additional ones for target area.
Might be also related to: https://github.com/magento/magento2/issues/34394 https://github.com/magento/magento2/issues/28193 https://github.com/magento/magento2/issues/31468 https://github.com/magento/magento2/pull/15042
The issue is applicable also for cases when we follow guides like this:
https://devdocs.magento.com/guides/v2.4/inventory/source-selection-algorithms.html#configure-dixml
But what is I want to add new algorithm that is available only in certain area? Then all other algorithms added by modules will be removed, it's unexpected behavior!!
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
- [ ] 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”.
Hi @ilnytskyi. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:
- Summary of the issue
- Information on your environment
- Steps to reproduce
- Expected and actual results
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.
- Join Magento Community Engineering Slack and ask your questions in #github channel.
:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
: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.
: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
Can confirm issue : I met the same problem with the graphql and the global area. Arguments were replaced.
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:
-
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
Details
If the issue has a valid description, the labelIssue: Format is validwill be added to the issue automatically. Please, edit issue description if needed, until labelIssue: Format is validappears. -
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add
Issue: Clear Descriptionlabel to the issue by yourself. -
[ ] 3. Add
Component: XXXXXlabel(s) to the ticket, indicating the components it may be related to. -
[ ] 4. Verify that the issue is reproducible on
2.4-developbranchDetails
- Add the comment@magento give me 2.4-develop instanceto deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-developbranch, please, add the labelReproduced 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: Confirmedonce verification is complete. -
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hi @ilnytskyi
Thank you for reporting the issue.
We are able to reproduce it on Magento 2.4-develop
Steps followed to reproduce this issue.
-
Create a custom module.
-
Create a global area di.xml.

-
Create di.xml in adminhtml area.

-
Create respective classes defined in di.xml

And

Now use TestB class in any other class and set a breakpoint in Constructor.
This $testObject should contains 3 values in $stringData arguments of Test Class.

Thanks
:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-1903 is successfully created for this GitHub issue.
: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.
Hi @ilnytskyi ! We just went through the issue and found that mentioned behavior is expected and documented on the DevDocs, please refer to https://devdocs.magento.com/guides/v2.4/extension-dev-guide/build/di-xml-file.html#argument-types page

@sidolov well, ok. But for some cases it's not suitable.
In my case I faced this issue when wanted to add some additional handlers for payment method in adminhtml area, and noticed that original ones are not present.
Would it be possible to improve DI with possibility to manage if new type should replace or extended/merge an array in different area? just like an attribute shared="true|false"
and maybe possibility to remove array items as in layout xml. That would make DI a lot more flexible.
@ilnytskyi Can you provide example of configuration that does not work for you. I believe that if you add base configuration to your area configuration, all should work as expected.
Add an attribute that will define how array merging is behaving is a good idea, we also think about it, but it will require complex implementation/testing. Feel free to submit PR with implementation if you want
@kandy my case if the same as I described and what magento team confirmed as a bug.
I believe that if you add base configuration to your area configuration, all should work as expected.
Yes, that exactly what I described in workaround section.
Just found a real-world case: a third party module wants to add an extensionAction to the product "read" action, but only for the webapi_rest environment in order to add some custom data to what that API produces. As a result, all the default extensionActions defined by Magento (such as the ones that save configurable products extension attributes) get wiped out.
@azambon Tell me that you were referring to the Amasty PriceHistory module ?
@azambon Tell me that you were referring to the Amasty PriceHistory module ?
@atty31 Yep, that's the one. I didn't mention which module it was because any module that tries to add an extensionAction would encounter the same problem, so naming one would not be useful in solving the issue.