commercetools / commercetools-sync-java

Java library for importing and syncing (taking care of changes) data into one or more commercetools projects from external data files or from another commercetools project.
https://commercetools.github.io/commercetools-sync-java
Apache License 2.0
32 stars 37 forks source link

draft returns Optional.empty() during errorCallback in ProductSyncOptions #1179

Closed InvasiveFiber97 closed 3 months ago

InvasiveFiber97 commented 3 months ago

Description

I'm using commertools-sync-java sdk to import products to commercetools project. I have a spring application. I've create a bean in configuration as

@Bean
@StepScope
ProductSync productSync(
        @Value("#{stepExecution.jobExecution}") JobExecution jobExecution) {

    ProductSyncOptions productSyncOptions = ProductSyncOptionsBuilder.of(ctConfig.getSphereClient())
            .errorCallback((syncException, draft, productProjection, updateActions) -> {
                    log.error("Error callback during product sync", syncException);
                    if (draft.isPresent()) {
                        ((List<ProductDraft>) jobExecution.getExecutionContext().get(FAILED_RESOURCE_KEY)).add(draft.get());
                        reportService.updateError(ERROR_UPDATE_PROCESS_SYNC, draft.get().getKey(),
                                syncException.getLocalizedMessage());
                    }
            }).build();
    return new ProductSync(productSyncOptions);
}

And doing the sync as mentioned in the docs CompletionStage<ProductSyncStatistics> syncStatisticsStage = productSync.sync(productDrafts);

However whenever error occurs and flow goes into errorCallback, it does not have draft inside it.

Expected Behaviour

The draft should return the failed product draft, in errorCallback.

Other Info : I'm using Spring batch the sync call is done in writer and productSync is defined as bean inside a configuration class as StepScope.

Please help me with this.

InvasiveFiber97 commented 3 months ago

@heshamMassoud / @ahmetoz would you be able to help me on above issue, please?

butenkor commented 3 months ago

Hi @InvasiveFiber97, without your error details its hard to tell what the issue is since as you can see here handleError, depending on the error type can sometimes pass a draft and sometimes not.

InvasiveFiber97 commented 3 months ago

I got error such as "Old Master Variant key not present" and "Unable to Update attribute update action" which does seem to return draft as per the reference in handleError. Thanks