@read_session
def list_bad_replicas_status(state=BadFilesStatus.BAD, rse_id=None, younger_than=None, older_than=None, limit=None, list_pfns=False, vo='def', session=None):
    '\n    List the bad file replicas history states. Method used by the rucio-ui.\n    :param state: The state of the file (SUSPICIOUS or BAD).\n    :param rse_id: The RSE id.\n    :param younger_than: datetime object to select bad replicas younger than this date.\n    :param older_than:  datetime object to select bad replicas older than this date.\n    :param limit: The maximum number of replicas returned.\n    :param vo: The VO to find replicas from.\n    :param session: The database session in use.\n    '
    result = []
    query = session.query(models.BadReplicas.scope, models.BadReplicas.name, models.BadReplicas.rse_id, models.BadReplicas.state, models.BadReplicas.created_at, models.BadReplicas.updated_at)
    if state:
        query = query.filter((models.BadReplicas.state == state))
    if rse_id:
        query = query.filter((models.BadReplicas.rse_id == rse_id))
    if younger_than:
        query = query.filter((models.BadReplicas.created_at >= younger_than))
    if older_than:
        query = query.filter((models.BadReplicas.created_at <= older_than))
    if limit:
        query = query.limit(limit)
    for badfile in query.yield_per(1000):
        if (badfile.scope.vo == vo):
            if list_pfns:
                result.append({'scope': badfile.scope, 'name': badfile.name, 'type': DIDType.FILE})
            else:
                result.append({'scope': badfile.scope, 'name': badfile.name, 'rse': get_rse_name(rse_id=badfile.rse_id, session=session), 'rse_id': badfile.rse_id, 'state': badfile.state, 'created_at': badfile.created_at, 'updated_at': badfile.updated_at})
    if list_pfns:
        reps = []
        for rep in list_replicas(result, schemes=None, unavailable=False, request_id=None, ignore_availability=True, all_states=True, session=session):
            pfn = None
            if ((rse_id in rep['rses']) and rep['rses'][rse_id]):
                pfn = rep['rses'][rse_id][0]
                if (pfn and (pfn not in reps)):
                    reps.append(pfn)
            else:
                reps.extend([item for row in rep['rses'].values() for item in row])
        list(set(reps))
        result = reps
    return result
List the bad file replicas history states. Method used by the rucio-ui.
:param state: The state of the file (SUSPICIOUS or BAD).
:param rse_id: The RSE id.
:param younger_than: datetime object to select bad replicas younger than this date.
:param older_than:  datetime object to select bad replicas older than this date.
:param limit: The maximum number of replicas returned.
:param vo: The VO to find replicas from.
:param session: The database session in use.
@read_session
def list_bad_replicas_status(state=BadFilesStatus.BAD, rse_id=None, younger_than=None, older_than=None, limit=None, list_pfns=False, vo='def', session=None):
    '\n    List the bad file replicas history states. Method used by the rucio-ui.\n    :param state: The state of the file (SUSPICIOUS or BAD).\n    :param rse_id: The RSE id.\n    :param younger_than: datetime object to select bad replicas younger than this date.\n    :param older_than:  datetime object to select bad replicas older than this date.\n    :param limit: The maximum number of replicas returned.\n    :param vo: The VO to find replicas from.\n    :param session: The database session in use.\n    '
    result = []
    query = session.query(models.BadReplicas.scope, models.BadReplicas.name, models.BadReplicas.rse_id, models.BadReplicas.state, models.BadReplicas.created_at, models.BadReplicas.updated_at)
    if state:
        query = query.filter((models.BadReplicas.state == state))
    if rse_id:
        query = query.filter((models.BadReplicas.rse_id == rse_id))
    if younger_than:
        query = query.filter((models.BadReplicas.created_at >= younger_than))
    if older_than:
        query = query.filter((models.BadReplicas.created_at <= older_than))
    if limit:
        query = query.limit(limit)
    for badfile in query.yield_per(1000):
        if (badfile.scope.vo == vo):
            if list_pfns:
                result.append({'scope': badfile.scope, 'name': badfile.name, 'type': DIDType.FILE})
            else:
                result.append({'scope': badfile.scope, 'name': badfile.name, 'rse': get_rse_name(rse_id=badfile.rse_id, session=session), 'rse_id': badfile.rse_id, 'state': badfile.state, 'created_at': badfile.created_at, 'updated_at': badfile.updated_at})
    if list_pfns:
        reps = []
        for rep in list_replicas(result, schemes=None, unavailable=False, request_id=None, ignore_availability=True, all_states=True, session=session):
            pfn = None
            if ((rse_id in rep['rses']) and rep['rses'][rse_id]):
                pfn = rep['rses'][rse_id][0]
                if (pfn and (pfn not in reps)):
                    reps.append(pfn)
            else:
                reps.extend([item for row in rep['rses'].values() for item in row])
        list(set(reps))
        result = reps
    return result