# Buggy code
def jobs(self, limit=50, skip=0, status=None, db_filter=None):
    """Attempt to get the jobs submitted to the backend.

    Args:
        limit (int): number of jobs to retrieve
        skip (int): starting index of retrieval
        status (None or JobStatus or str): only get jobs with this status,
            where status is e.g. `JobStatus.RUNNING` or `'RUNNING'`
        db_filter (dict): `loopback-based filter
            <https://loopback.io/doc/en/lb2/Querying-data.html>`_.
            This is an interface to a database ``where`` filter. Some
            examples of its usage are:

            Filter last five jobs with errors::

               job_list = backend.jobs(limit=5, status=JobStatus.ERROR)

            Filter last five jobs with counts=1024, and counts for
            states ``00`` and ``11`` each exceeding 400::

              cnts_filter = {'shots': 1024,
                             'qasms.result.data.counts.00': {'gt': 400},
                             'qasms.result.data.counts.11': {'gt': 400}}
              job_list = backend.jobs(limit=5, db_filter=cnts_filter)

            Filter last five jobs from 30 days ago::

               past_date = datetime.datetime.now() - datetime.timedelta(days=30)
               date_filter = {'creationDate': {'lt': past_date.isoformat()}}
               job_list = backend.jobs(limit=5, db_filter=date_filter)

    Returns:
        list(IBMQJob): list of IBMQJob instances

    Raises:
        IBMQBackendValueError: status keyword value unrecognized
    """
    backend_name = self.name()
    api_filter = {"backend.name": backend_name}
    if status:
        if isinstance(status, str):
            status = JobStatus[status]
        if status == JobStatus.RUNNING:
            this_filter = {"status": "RUNNING", "infoQueue": {"exists": False}}
        elif status == JobStatus.QUEUED:
            this_filter = {"status": "RUNNING", "infoQueue.status": "PENDING_IN_QUEUE"}
        elif status == JobStatus.CANCELLED:
            this_filter = {"status": "CANCELLED"}
        elif status == JobStatus.DONE:
            this_filter = {"status": "COMPLETED"}
        elif status == JobStatus.ERROR:
            this_filter = {"status": {"regexp": "^ERROR"}}
        else:
            raise IBMQBackendValueError(
                'unrecognized value for "status" keyword in job filter'
            )
        api_filter.update(this_filter)
    if db_filter:
        # status takes precedence over db_filter for same keys
        api_filter = {**db_filter, **api_filter}
    job_info_list = self._api.get_status_jobs(limit=limit, skip=skip, filter=api_filter)
    job_list = []
    for job_info in job_info_list:
        job_class = _job_class_from_job_response(job_info)
        if job_class is IBMQJobPreQobj:
            warnings.warn(
                "The result of job {} is in an old and no longer supported format, "
                "please resend the job with Qiskit 0.7".format(job_info.get("id")),
                DeprecationWarning,
            )
            continue

        is_device = not bool(self.configuration().simulator)
        job = job_class(
            self,
            job_info.get("id"),
            self._api,
            is_device,
            creation_date=job_info.get("creationDate"),
            api_status=job_info.get("status"),
        )
        job_list.append(job)
    return job_list


# Traceback (KeyError)
1:     b'Traceback (most recent call last):'
1:     b'  File "/home/travis/build/Qiskit/qiskit-terra/test/python/ibmq/test_ibmqjob.py", line 283, in test_get_jobs_filter_job_status'
1:     b"    self.log.info('match #%d: %s', i, job.result().status)"
1:     b'  File "/home/travis/build/Qiskit/qiskit-terra/qiskit/backends/ibmq/ibmqjob.py", line 210, in result'
1:     b'    return self._result_from_job_response(job_response)'
1:     b'  File "/home/travis/build/Qiskit/qiskit-terra/qiskit/backends/ibmq/ibmqjob.py", line 506, in _result_from_job_response'
1:     b'    _reorder_bits(job_response)'
1:     b'  File "/home/travis/build/Qiskit/qiskit-terra/qiskit/backends/ibmq/ibmqjob.py", line 546, in _reorder_bits'
1:     b"    for circuit_result in job_data['qasms']:"
1:     b"KeyError: 'qasms'"
1:     b''

# Fixed code
def jobs(self, limit=50, skip=0, status=None, db_filter=None):
    """Attempt to get the jobs submitted to the backend.

    Args:
        limit (int): number of jobs to retrieve
        skip (int): starting index of retrieval
        status (None or JobStatus or str): only get jobs with this status,
            where status is e.g. `JobStatus.RUNNING` or `'RUNNING'`
        db_filter (dict): `loopback-based filter
            <https://loopback.io/doc/en/lb2/Querying-data.html>`_.
            This is an interface to a database ``where`` filter. Some
            examples of its usage are:

            Filter last five jobs with errors::

               job_list = backend.jobs(limit=5, status=JobStatus.ERROR)

            Filter last five jobs with counts=1024, and counts for
            states ``00`` and ``11`` each exceeding 400::

              cnts_filter = {'shots': 1024,
                             'qasms.result.data.counts.00': {'gt': 400},
                             'qasms.result.data.counts.11': {'gt': 400}}
              job_list = backend.jobs(limit=5, db_filter=cnts_filter)

            Filter last five jobs from 30 days ago::

               past_date = datetime.datetime.now() - datetime.timedelta(days=30)
               date_filter = {'creationDate': {'lt': past_date.isoformat()}}
               job_list = backend.jobs(limit=5, db_filter=date_filter)

    Returns:
        list(IBMQJob): list of IBMQJob instances

    Raises:
        IBMQBackendValueError: status keyword value unrecognized
    """
    backend_name = self.name()
    api_filter = {"backend.name": backend_name}
    if status:
        if isinstance(status, str):
            status = JobStatus[status]
        if status == JobStatus.RUNNING:
            this_filter = {"status": "RUNNING", "infoQueue": {"exists": False}}
        elif status == JobStatus.QUEUED:
            this_filter = {"status": "RUNNING", "infoQueue.status": "PENDING_IN_QUEUE"}
        elif status == JobStatus.CANCELLED:
            this_filter = {"status": "CANCELLED"}
        elif status == JobStatus.DONE:
            this_filter = {"status": "COMPLETED"}
        elif status == JobStatus.ERROR:
            this_filter = {"status": {"regexp": "^ERROR"}}
        else:
            raise IBMQBackendValueError(
                'unrecognized value for "status" keyword in job filter'
            )
        api_filter.update(this_filter)
    if db_filter:
        # status takes precedence over db_filter for same keys
        api_filter = {**db_filter, **api_filter}
    job_info_list = self._api.get_status_jobs(limit=limit, skip=skip, filter=api_filter)
    job_list = []
    for job_info in job_info_list:
        job_class = _job_class_from_job_response(job_info)
        if job_class is IBMQJobPreQobj:
            warnings.warn(
                "The result of job {} is in a no longer supported format. "
                "These jobs will stop working after Qiskit 0.7. Save the results "
                "or send the job with Qiskit 0.7+".format(job_info.get("id")),
                DeprecationWarning,
            )

        is_device = not bool(self.configuration().simulator)
        job = job_class(
            self,
            job_info.get("id"),
            self._api,
            is_device,
            creation_date=job_info.get("creationDate"),
            api_status=job_info.get("status"),
        )
        job_list.append(job)
    return job_list