I'm getting a strange behavior with Sitecore 8.2 and commerce 8.2.1. Every time a custom minion runs it throws the following exception:

ERROR SQL:block:findentitiesinlist.Error: Message=Attempted to divide by zero.|Trace=   at Sitecore.Commerce.Plugin.SQL.FindEntitiesInListBlock.d__4.MoveNext()
System.DivideByZeroException: Attempted to divide by zero.
   at Sitecore.Commerce.Plugin.SQL.FindEntitiesInListBlock.d__4.MoveNext()

I decompiled the Sitecore.Commerce.Plugin.SQL plugin and noticed that it fails in the FindEntitiesInListBlock when the 'Take' property in the argument is 0: enter image description here

The reason why it fails is because when it is setting the PageCount property it tries to devide the count with the Take argument and if it is 0 it explains the DivideByZero exception.

CommerceList<CommerceEntity> commerceList = new CommerceList<CommerceEntity>()
          Name = arg.ListName,
          DisplayName = arg.ListName,
          CurrentPage = 1,
          TotalItemCount = num,
          PageCount = (int) Math.Round(Convert.ToDecimal((int) num / arg.Take)),
          SearchOptions = new SearchOption()
            Skip = arg.Skip,
            Take = arg.Take,
            ListMemberships = new List<string>()

What should be changed in the minion definition to prevent this error from happening? I don't see where the 'Take' argument is set. And just to be clear my code is not calling the FindEntitiesInList pipeline directly. I suspect that this is being called under the hood by Sitecore's own plugin

Here is my minion definition:

        "$type": "Sitecore.Commerce.Core.MinionPolicy, Sitecore.Commerce.Core",
        "WakeupInterval": "00:15:00",
        "ListToWatch": "NoFulfillmentList",
        "FullyQualifiedName": "MyType, MyAssembly",
        "ItemsPerBatch": 10,
        "SleepBetweenBatches": 500,
        "PolicyId": "7bb82d2a3adc9fd2cebf69b11f472d84",
        "Models": {
          "$type": "System.Collections.Generic.List`1[[Sitecore.Commerce.Core.Model, Sitecore.Commerce.Core]], mscorlib",
          "$values": [


The argument that sets it to 0 is in the pipeline argument invoke:

long listCount = await this.GetListCount(this.Policy.ListToWatch);
FulfillmentMinionArgument orderMinionArgument = new FulfillmentMinionArgument((await this.GetListIds<Order>(this.Policy.ListToWatch, Convert.ToInt32(listCount))).IdList, this.Policy.ListToWatch);

The way to fix that is to add an 'if' checking if listCount > 0 before calling the Run method to make sure it only runs when the list is not empty

if (listCount > 0)
      await minionPipeline.Run(ordersMinionArgument, executionContextOptions);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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