Generalize bulk_operations logic

LMS-11366

@nasthagiri @cpennington please review
Shouldn't L417-418 be moved after the try-except block below?  If `DuplicateItemError` is raised, we would needlessly mark the `bulk_record` dirty.