magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

ExtensibleDataObjectConverter::toFlatArray method overrides object data with it's extension attributes data

Open agata-maksymiuk opened this issue 5 months ago • 3 comments

Preconditions and environment

  • Magento 2.4.7-p3
  • Customer with custom extension attribute object, having the same getter methods as Customer object

Steps to reproduce

  1. Create Customer's custom attribute object with the same getter methods as Customer object - in my example, it's SomethingInterface with methods getId() and getCreatedAt(). Append it to the Customer object on afterGetById() plugin.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd"> <extension_attributes for="Magento\Customer\Api\Data\CustomerInterface"> <attribute code="something" type="Vendor\Module\Api\Data\SomethingInterface"/> </extension_attributes> </config>

  1. While creating a new cart for the customer (\Magento\Quote\Model\QuoteManagement::createCustomerCart), ExtensibleDataObjectConverter::toFlatArray method is being run, to copy data from Customer object to Quote object.

  2. At first, the method ExtensibleDataObjectConverter::toNestedArray creates a nested array from the Customer object, including it's extension attributes recursively, and the result comes like this:

{"id":6,"group_id":28,"default_billing":"6","default_shipping":"6","created_at":"2023-04-28 09:00:04","updated_at":"2025-06-16 12:59:28", "created_in":"Admin","email":"[email protected]","firstname":"i7l425ii","lastname":"0g8i0vl9","gender":0,"store_id":0,"website_id":2,"addresses":[], "disable_auto_group_change":0,"last_login":"2025-06-16 11:53:50","is_disabled":"0", "something":{"foo":true,"something_details":{"id":13,"created_at":"2025-04-11 11:04:28"}}}

  1. Then, the method \Magento\Framework\Convert\ConvertArray::toFlatArray creates a flat array from the array above, overriding the Customer object fields values from extension attribute fields values with the same name (id and created_at in this example).

{"id":13,"group_id":28,"default_billing":"6","default_shipping":"6","created_at":"2025-04-11 11:04:28","updated_at":"2025-06-16 12:59:28", "created_in":"Admin","email":"[email protected]","firstname":"i7l425ii","lastname":"0g8i0vl9","gender":0,"store_id":0,"website_id":2, "disable_auto_group_change":0,"last_login":"2025-06-16 11:53:50","is_disabled":"0", "foo":true}

Field id of the Customer now became 13 (was 6), it was overriden from something extension attribute field id.

Expected result

If Customer extension attribute is an object, it probably should be skipped, not flatten & merged with Customer object

Actual result

An error displays: Provided customer ID "6" isn't related to current customer address.

As current customer ID "became" 13 after conversion to the flat array, it does not match with customer 6 addresses parent ID and the new cart creation is failed.

Object field is overriden by field from it's extension attributes, if the name is the same.

Additional information

No response

Release note

No response

Triage and priority

  • [ ] 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”.

agata-maksymiuk avatar Jun 16 '25 14:06 agata-maksymiuk

Hi @agata-maksymiuk. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.


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.

m2-assistant[bot] avatar Jun 16 '25 14:06 m2-assistant[bot]

Hi @engcom-November. 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).
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • [ ] 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- 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-assistant[bot] avatar Jun 16 '25 16:06 m2-assistant[bot]

The same problem with ExtensibleDataObjectConverter::toFlatArray https://github.com/magento/magento2/issues/29288#issuecomment-1056912973

agata-maksymiuk avatar Jun 17 '25 07:06 agata-maksymiuk

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).
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • [ ] 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- 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-assistant[bot] avatar Jun 30 '25 11:06 m2-assistant[bot]

Hello @agata-maksymiuk,

Thanks for the report and collaboration!

We have tried to reproduce the issue in the latest development branch i.e. 2.4-develop and it seems the issue is not reproducible for us. We are able to create new cart id.

Please refer to the below custom module we have created to reproduce the issue:

Issue40001.zip

Let us know if missed anything.

Thanks

engcom-Hotel avatar Jun 30 '25 11:06 engcom-Hotel

Hello @agata-maksymiuk,

Gentle reminder to look into this https://github.com/magento/magento2/issues/40001#issuecomment-3018802336.

Thanks

engcom-Hotel avatar Jul 22 '25 06:07 engcom-Hotel

@engcom-Hotel Thank you for reply. I will prepare an example module to reproduce the issue as soon as I can.

agata-maksymiuk avatar Jul 29 '25 12:07 agata-maksymiuk

Hello @agata-maksymiuk,

Have you got a chance to prepare an example module to reproduce the issue?

Thanks

engcom-Hotel avatar Aug 21 '25 11:08 engcom-Hotel

Hello @agata-maksymiuk,

Gentle reminder for this issue.

Thanks

engcom-Hotel avatar Sep 01 '25 06:09 engcom-Hotel