Error Message: "That Object is Busy"

This message pops up when my addon’s code attempts to sell all the items in a bag (i.e., using

UseContainerItem(bagId, s)

When the message appears, the iteration continues as if everything was just fine. Indeed, it records the sale of every item in the bag as one would expect. However, one or more items are left in the bag.

Any advice?