Repository: Qiskit/qiskit

Issue:
Handling old-format jobs (test_get_jobs_filter_job_status)
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Information

We are experiencing some intermitent failures at `test.python.ibmq.test_ibmqjob.TestIBMQJob.test_get_jobs_filter_job_status` (specifically, seems to happen at premium):

https://travis-ci.org/Qiskit/qiskit-terra/jobs/461104008

```
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''
```

This seems to be because of the co-existence of different formats currently, and sort of accounted for - by 0.7, all jobs created and stored should have the same format. However, we should provide a cleaner way of dealing with pre-0.7 style jobs, revising the functions that retrieve them from the API (and emitting a warning if an old-style job cannot be parsed or similar).


### What is the expected behavior?



### Suggested solutions





Discussion:
lets just only work for the new jobs format

Resolving patch:
diff --git a/qiskit/backends/ibmq/ibmqbackend.py b/qiskit/backends/ibmq/ibmqbackend.py
--- a/qiskit/backends/ibmq/ibmqbackend.py
+++ b/qiskit/backends/ibmq/ibmqbackend.py
@@ -10,11 +10,12 @@
 This module is used for connecting to the Quantum Experience.
 """
 import logging
+import warnings
 
 from marshmallow import ValidationError
 
 from qiskit import QiskitError
-from qiskit.backends import BaseBackend, JobStatus
+from qiskit.backends import BaseBackend, JobStatus, JobError
 from qiskit.backends.models import BackendStatus, BackendProperties
 
 from .api import ApiError
@@ -160,6 +161,12 @@ def jobs(self, limit=50, skip=0, status=None, db_filter=None):
         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'),
@@ -178,6 +185,7 @@ def retrieve_job(self, job_id):
 
         Raises:
             IBMQBackendError: if retrieval failed
+            DeprecatedFormatJobError: if the job retrieved has a format pre 0.7
         """
         try:
             job_info = self._api.get_status_job(job_id)
@@ -188,6 +196,11 @@ def retrieve_job(self, job_id):
             raise IBMQBackendError('Failed to get job "{}":{}'
                                    .format(job_id, str(ex)))
         job_class = _job_class_from_job_response(job_info)
+        if job_class is IBMQJobPreQobj:
+            raise DeprecatedFormatJobError('The result of job {} is in an old and no '
+                                           'longer supported format, please resend the '
+                                           'job with Qiskit 0.7'.format(job_id))
+
         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'),
@@ -209,7 +222,12 @@ class IBMQBackendError(QiskitError):
 
 
 class IBMQBackendValueError(IBMQBackendError, ValueError):
-    """ Value errors thrown within IBMQBackend """
+    """Value errors thrown within IBMQBackend """
+    pass
+
+
+class DeprecatedFormatJobError(JobError):
+    """Retrieving responses pre-qobj is no longer supported."""
     pass
 
 


Test patch:
diff --git a/test/python/ibmq/test_ibmqjob.py b/test/python/ibmq/test_ibmqjob.py
--- a/test/python/ibmq/test_ibmqjob.py
+++ b/test/python/ibmq/test_ibmqjob.py
@@ -23,7 +23,7 @@
 from qiskit import IBMQ
 from qiskit import compile
 from qiskit.backends import JobStatus, JobError
-from qiskit.backends.ibmq.ibmqbackend import IBMQBackendError
+from qiskit.backends.ibmq.ibmqbackend import IBMQBackendError, DeprecatedFormatJobError
 from qiskit.backends.ibmq.ibmqjob import IBMQJob
 from qiskit.backends.ibmq import least_busy
 
@@ -258,7 +258,12 @@ def test_retrieve_job(self, qe_token, qe_url):
 
         qobj = compile(self._qc, backend)
         job = backend.run(qobj)
-        rjob = backend.retrieve_job(job.job_id())
+
+        try:
+            rjob = backend.retrieve_job(job.job_id())
+        except DeprecatedFormatJobError as err:
+            self.skipTest(err.message)
+
         self.assertTrue(job.job_id() == rjob.job_id())
         self.assertTrue(job.result().get_counts() == rjob.result().get_counts())
 
@@ -277,6 +282,7 @@ def test_get_jobs_filter_job_status(self, qe_token, qe_url):
         backend = least_busy(backends)
 
         job_list = backend.jobs(limit=5, skip=0, status=JobStatus.DONE)
+
         self.log.info('found %s matching jobs', len(job_list))
         for i, job in enumerate(job_list):
             self.log.info('match #%d: %s', i, job.result().status)