Skip to content

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

Open
@agata-maksymiuk

Description

@agata-maksymiuk

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":"asdf@example.org","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":"asdf@example.org","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”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue: ready for confirmationReported on 2.4.7-p3Indicates original Magento version for the Issue report.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    Status

    Ready for Confirmation

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions