magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

we can't save customer's customAtrribute with null or blank string value

Open KaushikChavda opened this issue 2 years ago • 14 comments

Preconditions and environment

  • Magento version
  • 2.4.5-p1
  • Anything else that would help a developer reproduce the bug
  • When you have a customer's customAttribute and you try to save it with following it should delete value from the varchar table as per magento 2.4.4 version but its not working on newer version of magento
$customer = $customerRepository->getById($customerId);
    $customer->setCustomAttribute('custom_attribute',"");
    $customerRepository->save($customer);

Steps to reproduce

  • When you have a customer's customAttribute and you try to save it with following it should delete value from the varchar table as per magento 2.4.4 version but its not working on newer version of magento
$customer = $customerRepository->getById($customerId);
    $customer->setCustomAttribute('custom_attribute',"");
    $customerRepository->save($customer);

However its update the value if there is value change

Expected result

should remove the entity value for that attribute.

Actual result

Nothing happens

Additional information

No response

Release note

No response

Triage and priority

  • [X] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • [X] 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”.

KaushikChavda avatar Jan 20 '23 09:01 KaushikChavda

Hi @KaushikChavda. 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.


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

: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 20 '23 09:01 m2-assistant[bot]

Hi @engcom-Bravo. 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 Jan 20 '23 09:01 m2-assistant[bot]

I believe this is a duplicate of https://github.com/magento/magento2/issues/36151

vacla avatar Jan 24 '23 00:01 vacla

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

    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 Jan 30 '23 04:01 m2-assistant[bot]

Verified the issue on Magento 2.4-develop instance and the issue is reproducible. Hence confirming the issue. On saving the customer's custom attribute with null value, customer is saved but the value is not updated. image

engcom-November avatar Jan 30 '23 05:01 engcom-November

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

github-jira-sync-bot avatar Jan 30 '23 05:01 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 Jan 30 '23 05:01 m2-assistant[bot]

@magento I am working on this

Vasudev-22 avatar Feb 21 '23 13:02 Vasudev-22

Is there an update on this issue?

janssensjelle avatar Apr 04 '23 07:04 janssensjelle

Hi, This issue is reproducible in Enterprise Edition. Was found a fix to resolve this, but waiting for an repo to push the code

Vasudev-22 avatar Apr 05 '23 04:04 Vasudev-22

Is there an update on this issue?

dimonpvt1236 avatar Jul 03 '23 13:07 dimonpvt1236

nothing?

yuriMartinsO avatar Dec 26 '23 20:12 yuriMartinsO

Having the same issue with custom attributes for customers. Can't save or change them

ibecmattb avatar Jan 04 '24 14:01 ibecmattb

I made a workaround for this issue:

--- Model/ResourceModel/CustomerRepository.php	2022-07-21 08:45:08.000000000 +0000
+++ Model/ResourceModel/CustomerRepository.php	2024-02-26 16:13:21.520401927 +0000
@@ -307,7 +307,13 @@
     {
         if (!empty($prevCustomerDataArr)) {
             foreach ($prevCustomerDataArr as $field => $value) {
-                $customerModel->setOrigData($field, $value);
+                if ($field === \Magento\Framework\Api\CustomAttributesDataInterface::CUSTOM_ATTRIBUTES) {
+                    foreach ($value as $attribute) {
+                        $customerModel->setOrigData($attribute['attribute_code'], $attribute['value']);
+                    }
+                } else {
+                    $customerModel->setOrigData($field, $value);
+                }
             }
         }
     }

mcjwsk avatar Feb 26 '24 16:02 mcjwsk

Any Adobe patch to this yet?

The following patch from @mcjwsk worked for me

I made a workaround for this issue:

--- Model/ResourceModel/CustomerRepository.php	2022-07-21 08:45:08.000000000 +0000
+++ Model/ResourceModel/CustomerRepository.php	2024-02-26 16:13:21.520401927 +0000
@@ -307,7 +307,13 @@
     {
         if (!empty($prevCustomerDataArr)) {
             foreach ($prevCustomerDataArr as $field => $value) {
-                $customerModel->setOrigData($field, $value);
+                if ($field === \Magento\Framework\Api\CustomAttributesDataInterface::CUSTOM_ATTRIBUTES) {
+                    foreach ($value as $attribute) {
+                        $customerModel->setOrigData($attribute['attribute_code'], $attribute['value']);
+                    }
+                } else {
+                    $customerModel->setOrigData($field, $value);
+                }
             }
         }
     }

JiyaadDolly avatar May 08 '24 17:05 JiyaadDolly