I would feel better if there were also a manual transaction around all the innards of grades.grade().  While there are calls to "with grades.manual_transaction()" within grades.grade(), if there are exceptions thrown from code outside of one of these with statements, the transaction.commit_manually will fail.  It requires that all transactions be either commited or rolled back.  If you're confident you found all possible sources of exceptions, then go ahead and wrap them individually.