'Returns the db_file dataset associated/needed by `dataset`, or `None`.'

def db_dataset_for(self, dbkey):

    if (self.history is None):
        return None
    if isinstance(self.history, bunch.Bunch):
        return None
    datasets = self.sa_session.query(self.app.model.HistoryDatasetAssociation).filter_by(deleted=False, history_id=self.history.id, extension='len')
    for ds in datasets:
        if (dbkey == ds.dbkey):
            return ds
    return None
