magento2: REST API: Cannot delete custom attribute from product

Cannot delete an existing product custom attribute through the rest API.

Preconditions

  1. Magento CE 2.1.8
  2. PHP 5.6.31

Steps to reproduce

  1. Have a custom attribute with an assigned value in a product
  2. PUT product update (/rest/all/V1/products/100030774) with custom attributes altered by either by assigning custom_attribute value None or removing the key/value

Expected result

  1. Expect for the custom attribute to be removed/deleted from the product custom_attribute list

Actual result

  1. Product doesn’t remove/delete. If value is assigned None/Null, I get this error:
Updating product: 100030774: Put Error: Error occurred during "custom_attributes" processing. Value is not set for attribute code "fridge_capacity" Error updating product:  HTTPError('400 Client Error: Bad Request',)

If key/value is removed from the custom_attributes, then the Put call goes through without error, but the key/value is still present within custom_attributes, unaltered.

All other values update using exactly the same mechanism/code without issue, can add/change custom attributes correctly. Just cannot delete the custom attributes.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 29 (18 by maintainers)

Most upvoted comments

But 2.2 isn’t released. And even when it is, the sheer magnitude of change involved means companies will be running 2.1 for a long time, until 2.2 is stable, bugfixed and all 3rd party extensions supported. This is insane.

Why is this closed? It’s not fixed in the current product codebase. It might be months or years before large sites migrate everything to (currently still in development ) 2.2.

@siliconalchemy , thank you for your report. The fix for this issue is already available on Magento 2.2.0 branch.

Confirmed this fix works when backported into 2.1.9. The path is different - vendor/magento/framework/Webapi/ServiceInputProcessor.php.

@orlangur Encouraging that process is improving. I still don’t understand why 2.1.x issues are fixed in dev and closed. If it’s a 2.1.x. issue and the fix isn’t breaking, why isn’t it applied to 2.1.x branch and released in the next point release?

@siliconalchemy this is already changed: no 2.1.x ticket closed with remark “fixed in develop” nowadays. Obviously there is no other way to apply all relevant fixes from develop to 2.1.x but discovering bugs and backporting fixes. Hope after 2.2 release bugfixes will be tracked better and delivered as 2.2.x in a timely manner.

Yet another bug fixed half a year ago that hasn’t made it into the stable tree. This project really needs to address the braindead policy of only ever making fixes into the dev branch until enough people complain about an issue. This is an enterprise product, companies commit to a branch for a long time for lots of good reasons. Fixing bugs in point releases is a good thing, people.

It’s passing this: {"attribute_code": "fridge_capacity", "value": null}

Here’s the complete json:

Updating product: 100030774: put - url: http://xxx.com/rest/all/V1/products/100030774 , data: {"product": {"sku": "100030774", "status": 1, "media_gallery_entries": [], "name": "Bosch WAN28201GB Washing Machine", "type_id": "simple", "price": 389.99, "attribute_set_id": 4, "updated_at": "2017-09-07 11:29:21", "visibility": 4, "options": [], "tier_prices": [], "custom_attributes": [{"attribute_code": "short_description", "value": "Bosch WAN28201GB 1400Rpm 8Kg A+++ With Ecosilence Drive - White"}, {"attribute_code": "manufacturer", "value": "10"}, {"attribute_code": "category_ids", "value": ["10126", "10127"]}, {"attribute_code": "options_container", "value": "container2"}, {"attribute_code": "required_options", "value": "0"}, {"attribute_code": "has_options", "value": "0"}, {"attribute_code": "url_key", "value": "bosch-wan28201gb"}, {"attribute_code": "tax_class_id", "value": "2"}, {"attribute_code": "gift_message_available", "value": "0"}, {"attribute_code": "height", "value": "848"}, {"attribute_code": "width", "value": "598"}, {"attribute_code": "depth", "value": "550"}, {"attribute_code": "model", "value": "WAN28201GB"}, {"attribute_code": "colour", "value": "145"}, {"attribute_code": "sm_featured", "value": "0"}, {"attribute_code": "group", "value": "Washing Machine"}, {"attribute_code": "build", "value": "2926"}, {"attribute_code": "warranty", "value": "2022"}, {"attribute_code": "energy_rating", "value": "2785"}, {"attribute_code": "size", "value": "2794"}, {"attribute_code": "fridge_capacity", "value": null}, {"attribute_code": "spinspeed", "value": "1400rpm Max spin speed"}, {"attribute_code": "spin_speed_rpm", "value": "1400"}], "created_at": "2017-09-07 11:29:21", "id": 82351, "product_links": [], "extension_attributes": {"stock_item": {"stock_id": 1, "qty": 27, "low_stock_date": null, "is_qty_decimal": true, "use_config_notify_stock_qty": true, "use_config_min_sale_qty": 1, "use_config_manage_stock": true, "backorders": 2, "min_sale_qty": 1, "show_default_notification_message": false, "max_sale_qty": 10000, "is_in_stock": true, "is_decimal_divided": false, "manage_stock": false, "item_id": 79318, "use_config_enable_qty_inc": true, "min_qty": 0, "qty_increments": 0, "notify_stock_qty": 1, "enable_qty_increments": false, "product_id": 82351, "stock_status_changed_auto": 0, "use_config_min_qty": true, "use_config_max_sale_qty": true, "use_config_qty_increments": true, "use_config_backorders": true}}}, "saveOptions": true}