@transactional_session
def update_bad_replicas_history(dids, rse_id, session=None):
    '\n    Update the bad file replicas history. Method only used by necromancer\n\n    :param dids: The list of DIDs.\n    :param rse_id: The rse_id.\n    :param session: The database session in use.\n    '
    for did in dids:
        try:
            result = session.query(models.RSEFileAssociation.state).filter_by(rse_id=rse_id, scope=did['scope'], name=did['name']).one()
            state = result.state
            if (state == ReplicaState.AVAILABLE):
                query = session.query(models.BadReplicas).filter_by(state=BadFilesStatus.BAD, rse_id=rse_id, scope=did['scope'], name=did['name'])
                query.update({'state': BadFilesStatus.RECOVERED, 'updated_at': datetime.utcnow()}, synchronize_session=False)
            elif (state != ReplicaState.BAD):
                try:
                    session.query(models.RSEFileAssociation.state).filter_by(rse_id=rse_id, scope=did['scope'], name=did['name'], state=ReplicaState.AVAILABLE).one()
                except NoResultFound:
                    update_replicas_states([{'scope': did['scope'], 'name': did['name'], 'rse_id': rse_id, 'state': ReplicaState.BAD}], session=session)
                    session.query(models.Source).filter_by(scope=did['scope'], name=did['name'], rse_id=rse_id).delete(synchronize_session=False)
            else:
                pass
        except NoResultFound:
            try:
                result = session.query(models.DataIdentifier.availability).filter_by(scope=did['scope'], name=did['name'], did_type=DIDType.FILE).one()
                state = result.availability
                final_state = None
                if (state == DIDAvailability.LOST):
                    final_state = BadFilesStatus.LOST
                elif (state == DIDAvailability.DELETED):
                    final_state = BadFilesStatus.DELETED
                elif (state == DIDAvailability.AVAILABLE):
                    final_state = BadFilesStatus.DELETED
                else:
                    print('Houston we have a problem.')
                    final_state = BadFilesStatus.DELETED
                query = session.query(models.BadReplicas).filter_by(state=BadFilesStatus.BAD, rse_id=rse_id, scope=did['scope'], name=did['name'])
                query.update({'state': final_state, 'updated_at': datetime.utcnow()}, synchronize_session=False)
            except NoResultFound:
                query = session.query(models.BadReplicas).filter_by(state=BadFilesStatus.BAD, rse_id=rse_id, scope=did['scope'], name=did['name'])
                query.update({'state': BadFilesStatus.LOST, 'updated_at': datetime.utcnow()}, synchronize_session=False)
Update the bad file replicas history. Method only used by necromancer

:param dids: The list of DIDs.
:param rse_id: The rse_id.
:param session: The database session in use.
@transactional_session
def update_bad_replicas_history(dids, rse_id, session=None):
    '\n    Update the bad file replicas history. Method only used by necromancer\n\n    :param dids: The list of DIDs.\n    :param rse_id: The rse_id.\n    :param session: The database session in use.\n    '
    for did in dids:
        try:
            result = session.query(models.RSEFileAssociation.state).filter_by(rse_id=rse_id, scope=did['scope'], name=did['name']).one()
            state = result.state
            if (state == ReplicaState.AVAILABLE):
                query = session.query(models.BadReplicas).filter_by(state=BadFilesStatus.BAD, rse_id=rse_id, scope=did['scope'], name=did['name'])
                query.update({'state': BadFilesStatus.RECOVERED, 'updated_at': datetime.utcnow()}, synchronize_session=False)
            elif (state != ReplicaState.BAD):
                try:
                    session.query(models.RSEFileAssociation.state).filter_by(rse_id=rse_id, scope=did['scope'], name=did['name'], state=ReplicaState.AVAILABLE).one()
                except NoResultFound:
                    update_replicas_states([{'scope': did['scope'], 'name': did['name'], 'rse_id': rse_id, 'state': ReplicaState.BAD}], session=session)
                    session.query(models.Source).filter_by(scope=did['scope'], name=did['name'], rse_id=rse_id).delete(synchronize_session=False)
            else:
                pass
        except NoResultFound:
            try:
                result = session.query(models.DataIdentifier.availability).filter_by(scope=did['scope'], name=did['name'], did_type=DIDType.FILE).one()
                state = result.availability
                final_state = None
                if (state == DIDAvailability.LOST):
                    final_state = BadFilesStatus.LOST
                elif (state == DIDAvailability.DELETED):
                    final_state = BadFilesStatus.DELETED
                elif (state == DIDAvailability.AVAILABLE):
                    final_state = BadFilesStatus.DELETED
                else:
                    print('Houston we have a problem.')
                    final_state = BadFilesStatus.DELETED
                query = session.query(models.BadReplicas).filter_by(state=BadFilesStatus.BAD, rse_id=rse_id, scope=did['scope'], name=did['name'])
                query.update({'state': final_state, 'updated_at': datetime.utcnow()}, synchronize_session=False)
            except NoResultFound:
                query = session.query(models.BadReplicas).filter_by(state=BadFilesStatus.BAD, rse_id=rse_id, scope=did['scope'], name=did['name'])
                query.update({'state': BadFilesStatus.LOST, 'updated_at': datetime.utcnow()}, synchronize_session=False)