From 09cc1df6babaf90ea0b0a6fd926f8013822a31ed Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Thu, 1 Jun 2023 11:10:15 -0500 Subject: [PATCH] fix: raise most recent exception when not able to fetch query job after starting the job (#1362) * fix: raise most recent exception when not able to fetch query job after starting the job Towards internal issue 247809965 * update unit test * revert most changes to the test and explain why we're looking for a different exception from the original 'conflict' --- google/cloud/bigquery/_job_helpers.py | 2 +- tests/unit/test_client.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/google/cloud/bigquery/_job_helpers.py b/google/cloud/bigquery/_job_helpers.py index 33fc72261..57846b190 100644 --- a/google/cloud/bigquery/_job_helpers.py +++ b/google/cloud/bigquery/_job_helpers.py @@ -105,7 +105,7 @@ def do_query(): timeout=timeout, ) except core_exceptions.GoogleAPIError: # (includes RetryError) - raise create_exc + raise else: return query_job else: diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py index c155e2bc6..cf0aa4028 100644 --- a/tests/unit/test_client.py +++ b/tests/unit/test_client.py @@ -5092,12 +5092,14 @@ def test_query_job_rpc_fail_w_conflict_random_id_job_fetch_fails(self): QueryJob, "_begin", side_effect=job_create_error ) get_job_patcher = mock.patch.object( - client, "get_job", side_effect=DataLoss("we lost yor job, sorry") + client, "get_job", side_effect=DataLoss("we lost your job, sorry") ) with job_begin_patcher, get_job_patcher: - # If get job request fails, the original exception should be raised. - with pytest.raises(Conflict, match="Job already exists."): + # If get job request fails but supposedly there does exist a job + # with this ID already, raise the exception explaining why we + # couldn't recover the job. + with pytest.raises(DataLoss, match="we lost your job, sorry"): client.query("SELECT 1;", job_id=None) def test_query_job_rpc_fail_w_conflict_random_id_job_fetch_succeeds(self):