Handle duplicate key error in task