commercetools / commercetools/nodejs

[sync-actions] Compare only id and typeId fields when syncing references

Open
#1,253 0 comments 1 reaction 0 assignees View on GitHub
Type: Bug
Dominant language
JavaScript
Stars
77
Forks
70
PR merge metrics
No merged PRs in 30d

Description

When syncing attributes with `SET of REFERENCE` type it should compare only fields `id` and `typeId`. For example:

If the attribute before and after looks like this:
```js
{
name: 'setOfReference',
value: [{
id: '517321b8-7e3f-4427-ac5e-9d9001d69dc4',
typeId: 'product'
}, {
id: 'f49aceda-145b-4975-af1b-a8c782b54354',
typeId: 'product'
}]
}
```
It won't generate any update actions, which is correct.

But if the `before` looks like this:
```js
{
name: 'setOfReference',
value: [{
id: '517321b8-7e3f-4427-ac5e-9d9001d69dc4',
typeId: 'product',
obj: { /** resolved product */ }
}, {
id: 'f49aceda-145b-4975-af1b-a8c782b54354',
typeId: 'product',
obj: { /** resolved product */ }
}]
}
```

It will generate update action:
```js
{
"action": {
"action": "setAttribute",
"variantId": 1,
"name": "packageContents",
"value": [{
"typeId": "product",
"id": "517321b8-7e3f-4427-ac5e-9d9001d69dc4"
}, {
"typeId": "product",
"id": "f49aceda-145b-4975-af1b-a8c782b54354"
}],
"staged": true
}
}
```

Which is wrong because SET items were not changed so the API will throw an error:
```
"message": "A duplicate combination of the variant values (sku, key, images, prices, attributes) exists.",
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.