magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

AbstractAddress setData('custom_attributes', AttributeValue[]) breaks customAttributes

Open victortodoran opened this issue 4 years ago • 30 comments

Preconditions (*)

  1. Magento 2.4.1

Steps to reproduce (*)

  1. Add custom attribute on customer address
  2. Call $address->setCustomAttributes('custom_attributes', $attributes) where $attributes is Magento\Framework\Api\AttributeValue Note that this is done several times in the checkout process if the custom attribute is added on the payload(i.e is present in the form). For example in \Magento\Quote\Model\ShippingMethodManagement::estimateByExtendedAddress()

Expected result (*)

  1. Custom attributes are added on the entity with their initial values

Actual result (*)

  1. The value of the custom attributes also contains the attribute code. This can be easily be debugged starting from AbstractAddress::setData() AbstractExtensibleModel::setData() and finally AbstractExtensibleModel::filterCustomAttributes() to this lines
foreach ($data[self::CUSTOM_ATTRIBUTES] as $code => $value) {
            if (!($value instanceof \Magento\Framework\Api\AttributeInterface)) {
                $data[self::CUSTOM_ATTRIBUTES][$code] = $this->customAttributeFactory->create()
                    ->setAttributeCode($code)
                    ->setValue($value);
            }
        }

where $value is an array that contains both the code and the value of the attribute because of this line in AbstractAddress::setData() $attribute = is_array($attribute) ? $attribute : $attribute->__toArray();

I don't know what to say about the severity. This is pretty severe in my book, but the levels only seem to take into account a clean Magento install which I bet there isn't a single one in production.


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”.

victortodoran avatar Jan 14 '21 11:01 victortodoran

Hi @victortodoran. Thank you for your report. To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

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

Please, add a comment to assign the issue: @magento I am working on this


: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, please 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

m2-assistant[bot] avatar Jan 14 '21 11:01 m2-assistant[bot]

I can confirm this is happening on Magento 2.4.1

barbazul avatar Jan 29 '21 11:01 barbazul

It looks like everything started with this commit https://github.com/magento/magento2/commit/91d61bdc5e5b85dcc5b51f7b539055e187a16790 which was meant to allow the multiline custom attributes to be saved

barbazul avatar Jan 29 '21 11:01 barbazul

@barbazul thanks for taking the time to confirm this.

victortodoran avatar Jan 30 '21 20:01 victortodoran

This issue still has the status Ready For Confirmation. Why is that?

victortodoran avatar Feb 19 '21 07:02 victortodoran

I can confirm this is happening on Magento 2.4.1 (Magento Cloud)

Summary of the issue The custom address attributes doesn't save information as expected.

Information on your environment The error was confirmed on a clean Magento 2.4.1 installation.

Steps to reproduce:

  1. Create a client address atribute type "input_text" and another type "dropdown"
  2. Make a purchase and check the attributes on the admin.
  3. The error its visible on the admin when you edit the address of the order on guest purchases.
  4. The error can also be seen on the admin when you edit the client address. on registered customers purchases

Expected and actual results The custom address attributes doesn't save information as expected. You can see attach files.

We have a open ticket in Magento Cloud Help Center for this issue: https://support.magento.com/hc/en-us/requests/381435

@magento-admin do you have a patch for this? it seems that in Magento 2.4.2 it is solved.

Regards, Maximiliano.

issueEkono_1 issueEkono_2 issueEkono_3

maxosoriojamut avatar Mar 02 '21 23:03 maxosoriojamut

Found this bug today, upgrading to 2.4.2 an existing website that has custom attributes for customer address.

Since i'm not using multiline custom attributes i simply made a patch to remove the changes from commit https://github.com/magento/magento2/commit/91d61bdc5e5b85dcc5b51f7b539055e187a16790, if someone needs it:

Index: vendor/magento/module-customer/Model/Address/AbstractAddress.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/vendor/magento/module-customer/Model/Address/AbstractAddress.php b/vendor/magento/module-customer/Model/Address/AbstractAddress.php
--- a/vendor/magento/module-customer/Model/Address/AbstractAddress.php	(date 1615480763891)
+++ b/vendor/magento/module-customer/Model/Address/AbstractAddress.php	(date 1615480763891)
@@ -281,11 +281,6 @@
             $key = $this->_implodeArrayField($key);
         } elseif (is_array($value) && $this->isAddressMultilineAttribute($key)) {
             $value = $this->_implodeArrayValues($value);
-        } elseif (self::CUSTOM_ATTRIBUTES === $key && is_array($value)) {
-            foreach ($value as &$attribute) {
-                $attribute = is_array($attribute) ? $attribute : $attribute->__toArray();
-                $attribute = $this->processCustomAttribute($attribute);
-            }
         }
 
         return parent::setData($key, $value);

slackerzz avatar Mar 11 '21 14:03 slackerzz

Found this bug today, upgrading to 2.4.2 an existing website that has custom attributes for customer address.

Since i'm not using multiline custom attributes i simply made a patch to remove the changes from commit 91d61bd, if someone needs it:

Index: vendor/magento/module-customer/Model/Address/AbstractAddress.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/vendor/magento/module-customer/Model/Address/AbstractAddress.php b/vendor/magento/module-customer/Model/Address/AbstractAddress.php
--- a/vendor/magento/module-customer/Model/Address/AbstractAddress.php	(date 1615480763891)
+++ b/vendor/magento/module-customer/Model/Address/AbstractAddress.php	(date 1615480763891)
@@ -281,11 +281,6 @@
             $key = $this->_implodeArrayField($key);
         } elseif (is_array($value) && $this->isAddressMultilineAttribute($key)) {
             $value = $this->_implodeArrayValues($value);
-        } elseif (self::CUSTOM_ATTRIBUTES === $key && is_array($value)) {
-            foreach ($value as &$attribute) {
-                $attribute = is_array($attribute) ? $attribute : $attribute->__toArray();
-                $attribute = $this->processCustomAttribute($attribute);
-            }
         }
 
         return parent::setData($key, $value);

Thanks @slackerzz!

ZIPITRO avatar Apr 29 '21 06:04 ZIPITRO

Hi @engcom-Lima. 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).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - 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 15 '21 11:06 m2-assistant[bot]

Hi @engcom-Delta. 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).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - 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 29 '21 07:06 m2-assistant[bot]

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).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - 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 Jul 19 '21 11:07 m2-assistant[bot]

@magento give me 2.4-develop instance

engcom-Hotel avatar Sep 22 '21 13:09 engcom-Hotel

Hi @engcom-Hotel. Thank you for your request. I'm working on Magento instance for you.

Hi @engcom-Hotel, here is your Magento Instance: https://16d30920407fe7280410e4814aea87b6-2-4-develop.instances.magento-community.engineering Admin access: https://16d30920407fe7280410e4814aea87b6-2-4-develop.instances.magento-community.engineering/admin_b34e Login: 058a3638 Password: b6d16030587b

@magento give me 2.4-develop instance

engcom-Hotel avatar Sep 23 '21 06:09 engcom-Hotel

Hi @engcom-Hotel. Thank you for your request. I'm working on Magento instance for you.

Hi @engcom-Hotel, here is your Magento Instance: https://16d30920407fe7280410e4814aea87b6-2-4-develop.instances.magento-community.engineering Admin access: https://16d30920407fe7280410e4814aea87b6-2-4-develop.instances.magento-community.engineering/admin_7683 Login: 60996cfe Password: f6755d7eaa97

Hello @victortodoran,

We have tried to reproduce the issue in Magento 2.4-develop branch with the steps mentioned in comment. But the issue is not reproducible. Please have a look into below screenshots for reference:

Customer Attribute page

image

Admin Billing Order Edit page

image

Admin Shiping Order Edit page

image

Please let us know in case we have missed anything in order to reproduce the issue.

Thanks

engcom-Hotel avatar Sep 23 '21 07:09 engcom-Hotel

Hello @victortodoran,

We have noticed that this issue has not been updated for a period of 14 Days. Hence we assume that this issue is fixed now, so we are closing it. Please raise a fresh ticket if you need more assistance on this.

Regards

engcom-Hotel avatar Oct 07 '21 07:10 engcom-Hotel

This issue is still there after 2 years.

  • \Magento\Customer\Model\Address\AbstractAddress::setData l.284 is still converting custom_attributes into an array to process the private function "processCustomAttribute"

  • being interpreted as image

  • causing save in DB as : image

@victortodoran are you still facing this issue on 2.4.4-p2 aswell?

theozzz avatar Aug 20 '23 12:08 theozzz

I approve that on 2.4.6 this issue is still too: image

Litvinenko-Sergey avatar Nov 07 '23 14:11 Litvinenko-Sergey

Hello @Litvinenko-Sergey,

Thanks for the update, we are opening this issue for further analysis.

engcom-November avatar Nov 08 '23 11:11 engcom-November

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- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - 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 Nov 08 '23 11:11 m2-assistant[bot]

Hello @Litvinenko-Sergey,

Thank you for the report!

We have tried to reproduce this on vanilla installation of 2.4-develop. We created two custom address attributes one with text and one with dropdown, as mentioned here https://github.com/magento/magento2/issues/31644#issuecomment-789300004, but we are able to save the value of the custom attributes without any issues. Please take a look at the screenshot below: image

We also checked with the debugger: image And we didn't see any array returned for the value attribute.

Please let us know if we are missing anything.

Thank you.

engcom-November avatar Nov 08 '23 11:11 engcom-November

image I reproduced it on vanilla magento 2.4.6. I created a simple module that helps you to reproduce this bug: Litvinenko.zip You just need to install this module and create an order on frontend like guest.

Litvinenko-Sergey avatar Nov 08 '23 14:11 Litvinenko-Sergey

Hello @Litvinenko-Sergey,

Thank you for the quick reply!

We were able to reproduce this issue on 2.4-develop. We have used your custom module to reproduce this issue. Please take a look at the screenshot below: The custom address attribute value is not being saved. image

And we can see that the value also has custom attribute code. Screenshot 2023-11-13 at 5 09 50 PM

Hence confirming this issue.

Thank you.

engcom-November avatar Nov 15 '23 14:11 engcom-November

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-10568 is successfully created for this GitHub issue.

github-jira-sync-bot avatar Nov 15 '23 14:11 github-jira-sync-bot

:white_check_mark: Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

m2-assistant[bot] avatar Nov 15 '23 14:11 m2-assistant[bot]

:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-10568

github-jira-sync-bot avatar Nov 15 '23 14:11 github-jira-sync-bot

Hi @victortodoran,

Adobe Commerce Engineering team started working on this issue. We will reach out to you if we need more information and you will get notified once the issue is fixed. Please leave comments for any further questions.

Thank you!

engcom-Bravo avatar Jun 17 '25 09:06 engcom-Bravo