From 5b6612096ac9782df74b0fec7dd7a5c99608c629 Mon Sep 17 00:00:00 2001 From: Kevin Tian Date: Thu, 16 Nov 2023 14:56:36 -0500 Subject: [PATCH] Fix BYOB job results bytes typing issue (#1220) * try/except raw result truncation * catch typeError * revert try/except, use response.text * update unit test --- qiskit_ibm_runtime/runtime_job.py | 2 +- releasenotes/notes/byte-result-bug-7afb5abe813f5b1b.yaml | 6 ++++++ test/unit/test_jobs.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/byte-result-bug-7afb5abe813f5b1b.yaml diff --git a/qiskit_ibm_runtime/runtime_job.py b/qiskit_ibm_runtime/runtime_job.py index 80b77f3f5..297933ef6 100644 --- a/qiskit_ibm_runtime/runtime_job.py +++ b/qiskit_ibm_runtime/runtime_job.py @@ -166,7 +166,7 @@ def _download_external_result(self, response: Any) -> Any: if "url" in result_url_json: url = result_url_json["url"] result_response = requests.get(url, timeout=10) - return result_response.content + return result_response.text return response except json.JSONDecodeError: return response diff --git a/releasenotes/notes/byte-result-bug-7afb5abe813f5b1b.yaml b/releasenotes/notes/byte-result-bug-7afb5abe813f5b1b.yaml new file mode 100644 index 000000000..66e9d3c31 --- /dev/null +++ b/releasenotes/notes/byte-result-bug-7afb5abe813f5b1b.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixed an issue where canceled and failed jobs would return an invalid result that + resulted in a type error, preventing the actual error from being returned + to the user. \ No newline at end of file diff --git a/test/unit/test_jobs.py b/test/unit/test_jobs.py index 54684ecaa..af28cadfb 100644 --- a/test/unit/test_jobs.py +++ b/test/unit/test_jobs.py @@ -277,7 +277,7 @@ def test_download_external_job_result(self, service): job = run_program(service=service) with mock_wait_for_final_state(service, job): mock_response = MagicMock() - mock_response.content = "content-from-external-url" + mock_response.text = "content-from-external-url" request_mock.get.return_value = mock_response with mock_wait_for_final_state(service, job): job.wait_for_final_state()