Skip to content

Bug in DI generation: array arguments got replaced instead of merging when modified from different area #34464

@ilnytskyi

Description

@ilnytskyi

Preconditions (*)

  1. Create a configurable object or virtual type e.g. composite
  2. It's impossible to add new items into array argument for different area.
  3. 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

Selection_318
the arguments will be replaced
Selection_319

Steps to reproduce (*)

  1. 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>
  1. 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 (*)

  1. 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 (*)

  1. The handlers array 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:
#34394
#28193
#31468
#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”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: FrameworkComponent: Framework/AppIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: ready for groomingReported on 2.4.xIndicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject itfeature request

    Type

    No type

    Projects

    Status

    Ready for Grooming

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions