3

When executing the pipeline IAssociateCategoryToParentPipeline, there is a step that checks if there are any validation errors in CommerceContext.GetMessages().

This will cause an update to fail even if the messages were in place before the pipeline was initiated, which seems counterintuitive.

Question:

Is there a way to "refresh" the commerce context, or create a clone of it with an empty message list?

Details:

  • Observed in XC 9.0-Update 1.

  • AssociateCategoryToParentPipeline calls AssociateCategoryToParentBlock, which call CreateRelatationshipCommand.

  • CreateRelationshipCommand.Process calls the static method Command.PerformTransaction, and that calls ValidatateTransaction.
  • ValidationTransaction looks for the existence of a message with a code of "ValidationError", and if one is found, rolls back the transaction. So as long as there are any ValidationErrors in this list, any call to this command, and by extension AssociateCategoryToParentPipeline, will fail to persist updates.
1

2 Answers 2

2

I would suggest understanding what is an initial issue, that adds this ValidationError message to your context.

However, if you are writing initial import that requires a huge amount of entities to be imported it's better to clean context periodically to free memory.

You can use the following snippet:

context.CommerceContext = new CommerceContext(context.CommerceContext.Logger, context.CommerceContext.TelemetryClient)
{
    GlobalEnvironment = context.CommerceContext.GlobalEnvironment,
    Environment = context.CommerceContext.Environment,
    Headers = context.CommerceContext.Headers
};
1
  • Validation error was from a "delete relationship" pipeline call that didn't check if the relationship existed. I agree that should be tightened, but wanted to understand the pattern for isolating these operations. Thanks. Commented May 21, 2019 at 13:59
3

Best way is to use a new CommerceContext for each call.

If that isn’t feasible you can use the clear methods, e.g:

 context.CommerceContext.ClearEntities();
 context.CommerceContext.ClearModels();
 context.CommerceContext.ClearObjects();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.