commercetools-sdk-java-v2 icon indicating copy to clipboard operation
commercetools-sdk-java-v2 copied to clipboard

Question concerning com/commercetools/api/models/product/ProductSetAttributeAction.java

Open jloehl opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? Please describe. We are currently implementing a custom editing application to edit products in commercetools. We bundle the update actions for a certain group of attributes. But when we leave a attribute empty in the editing form (which isn't a mandatory attribute) we get an exception from commercetools with a message like:

"Cannot remove attribute 'product-v1_text_field' because it does not exist on product with name 'LocalizedString(Map(de_DE -> A nice Product name))'."

All other product updates in the same request are not performed as well.

But for us it doesn't seem like an error. We try to write an empty value or null in an attribute that doesn't exist on the product. If nothing happens, that's just the behavior our stakeholders expect. But the other attributes that have correct values should be added to the product.

Describe the solution you'd like Is it possible to handle this exception using the sdk so that empty values that do not exist on the product are ignored, but all other attributes are updated?

Or is there a best practice for this with the current version of the SDK that we just didn't come up with?

jloehl avatar Jul 15 '22 08:07 jloehl

When sending an SetAttributeAction which omits the value, the attribute will be removed from the product variant. But if the product variant doesn't have this attribute at all you are receiving this error. The API will also reject the whole request if it can't process all updates in the request. So SDK wise we can't prevent this.

The best practive to avoid this kind of error you would have to only send updates for existing attributes. Another option could be to use the Import API.

Besides as this is actually a non changing update you could send a feature request through our support, that removal of non existing attributes may not fail.

jenschude avatar Jul 18 '22 06:07 jenschude