commercetools / commercetools-project-sync

Dockerized CLI application which allows to automatically sync different resources between commercetools projects
44 stars 25 forks source link

[Price] Customer group id is used instead of key #239

Closed jortizsao closed 3 years ago

jortizsao commented 3 years ago

Hi :)

We are trying to sync the products between projects and the sync fails because our variants include prices for some customer groups, and the sync process is trying to reference the customer group in the target project using the customer group id, and thus, they product sync is failing.

Error:

[ForkJoinPool.commonPool-worker-0] ERROR com.commercetools.project.sync.product.ProductSyncer - Error when trying to sync product. Existing key: <<not present>>. Update actions: []
com.commercetools.sync.commons.exceptions.SyncException: Failed to process the ProductDraft with key:'335'. Reason: com.commercetools.sync.commons.exceptions.ReferenceResolutionException: Failed to resolve 'customer-group' reference on PriceDraft with country:'null' and value: 'USD 636'. Reason: Customer Group with key '1bf15ba9-1b1f-4e3f-a61d-57bc241cc3ba' does not exist.
    at com.commercetools.sync.products.ProductSync.lambda$syncDraft$17(ProductSync.java:375)
    at java.util.concurrent.CompletableFuture.uniExceptionally(CompletableFuture.java:870)
    at java.util.concurrent.CompletableFuture$UniExceptionally.tryFire(CompletableFuture.java:852)
    at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
    at java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:1962)
    at io.sphere.sdk.utils.CompletableFutureUtils.lambda$transferResult$0(CompletableFutureUtils.java:84)
    at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:760)
    at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:736)
    at java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:443)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.util.concurrent.CompletionException: com.commercetools.sync.commons.exceptions.ReferenceResolutionException: Failed to resolve 'customer-group' reference on PriceDraft with country:'null' and value: 'USD 636'. Reason: Customer Group with key '1bf15ba9-1b1f-4e3f-a61d-57bc241cc3ba' does not exist.
    at java.util.concurrent.CompletableFuture.encodeRelay(CompletableFuture.java:326)
    at java.util.concurrent.CompletableFuture.completeRelay(CompletableFuture.java:338)
    at java.util.concurrent.CompletableFuture.uniRelay(CompletableFuture.java:911)
    at java.util.concurrent.CompletableFuture.uniCompose(CompletableFuture.java:953)
    at java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:926)
    ... 10 more

Price in the source project

{
  "value": {
    "type": "centPrecision",
    "currencyCode": "USD",
    "centAmount": 63600,
    "fractionDigits": 2
  },
  "id": "f60c2647-9df8-4017-896f-ae7b1495acf1",
  "customerGroup": {
    "typeId": "customer-group",
    "id": "1bf15ba9-1b1f-4e3f-a61d-57bc241cc3ba"
  },
  "custom": {
    "type": {
      "typeId": "type",
      "id": "04495716-931a-4944-a3f0-74694812f49c"
    },
    "fields": {
      "discountAmount": "-20%",
      "discountLabel": "VIP Discount"
    }
  }
}

Customer group in source project

{
  "id": "1bf15ba9-1b1f-4e3f-a61d-57bc241cc3ba",
  "version": 3,
  "createdAt": "2019-04-11T08:45:50.967Z",
  "lastModifiedAt": "2019-05-21T14:10:35.574Z",
  "lastModifiedBy": {
    "isPlatformClient": true,
    "user": {
      "typeId": "user",
      "id": "0533a1ee-fd63-49e8-9a7e-223c9e42032a"
    }
  },
  "createdBy": {
    "isPlatformClient": true,
    "user": {
      "typeId": "user",
      "id": "35023530-6f47-4be0-a092-525a32160c5f"
    }
  },
  "name": "VIP",
  "key": "Vip"
}

Maybe, the customer group should be fetched by id in the source project, and referenced by key in the target project?

butenkor commented 3 years ago

Hi @jortizsao Good to see you again :) I think the fix might be to extend the query here with another expansion on the customer group: https://github.com/commercetools/commercetools-project-sync/blob/46c96c96af6903fd3fa738cf72e83258517bc955/src/main/java/com/commercetools/project/sync/product/ProductSyncer.java#L287

jortizsao commented 3 years ago

Hi @jortizsao Good to see you again :) I think the fix might be to extend the query here with another expansion on the customer group:

yes, good to see you @butenkor :) and thank you for the quick reply! Yes, you are right, expanding the customerGroup within the price should be enough to get the key

butenkor commented 3 years ago

We will fix it within the next 9 working days ;)

jortizsao commented 3 years ago

Thank you @butenkor ! no rush :)

butenkor commented 3 years ago

Btw. we changed the concept and due to the performance reasons we will not be using expansion anymore.

praveenkumarct commented 3 years ago

This issue has been addressed as part of our latest release 3.11.0.