Skip to content

Commit

Permalink
fix: fix and reformat job retry tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kiraksi committed Jan 29, 2024
1 parent 55d65f7 commit 015bb53
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
10 changes: 2 additions & 8 deletions google/cloud/bigquery/job/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1554,8 +1554,6 @@ def result( # type: ignore # (incompatible with supertype)
)

first = True
if self.state is None:
self._begin(retry=retry, timeout=timeout)

def do_get_result():
nonlocal first
Expand Down Expand Up @@ -1583,18 +1581,14 @@ def do_get_result():
self._retry_do_query = retry_do_query
self._job_retry = job_retry

super(QueryJob, self).result(retry=retry, timeout=timeout)

# Since the job could already be "done" (e.g. got a finished job
# via client.get_job), the superclass call to done() might not
# set the self._query_results cache.
if self._query_results is None or not self._query_results.complete:
self._reload_query_results(retry=retry, timeout=timeout)

# jobs.getQueryResults should be called before jobs.get. The
# jobs.getQueryResults request will raise an exception for
# failed jobs. This means our job retry mechanism can start
# earlier without a wasted call to jobs.get.
super(QueryJob, self).result(retry=retry, timeout=timeout)

if retry_do_query is not None and job_retry is not None:
do_get_result = job_retry(do_get_result)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_job_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def test_retry_failed_jobs_after_retry_failed(client):
retry=DEFAULT_RETRY,
job_retry=DEFAULT_JOB_RETRY,
)
#TODO: different test to test if it retries until it times out
# TODO: different test to test if it retries until it times out
with pytest.raises(google.api_core.exceptions.RetryError):
list(rows) # Trigger the initial retry failure

Expand Down

0 comments on commit 015bb53

Please sign in to comment.