@@ -514,7 +514,7 @@ def query_and_wait(
514514 # Some API parameters aren't supported by the jobs.query API. In these
515515 # cases, fallback to a jobs.insert call.
516516 if not _supported_by_jobs_query (request_body ):
517- iterator = _wait_or_cancel (
517+ return _wait_or_cancel (
518518 query_jobs_insert (
519519 client = client ,
520520 query = query ,
@@ -533,11 +533,9 @@ def query_and_wait(
533533 retry = retry ,
534534 page_size = page_size ,
535535 max_results = max_results ,
536+ query_results_format = query_results_format ,
536537 callback = callback ,
537538 )
538- if query_results_format is not None :
539- iterator ._query_results_format = query_results_format
540- return iterator
541539
542540 path = _to_query_path (project )
543541
@@ -601,18 +599,16 @@ def do_query():
601599 # remaining pages) by waiting for the query to finish and calling
602600 # client._list_rows_from_query_results directly. Need to update
603601 # RowIterator to fetch destination table via the job ID if needed.
604- iterator = _wait_or_cancel (
602+ return _wait_or_cancel (
605603 _to_query_job (client , query , job_config , response ),
606604 api_timeout = api_timeout ,
607605 wait_timeout = wait_timeout ,
608606 retry = retry ,
609607 page_size = page_size ,
610608 max_results = max_results ,
609+ query_results_format = query_results_format ,
611610 callback = callback ,
612611 )
613- if query_results_format is not None :
614- iterator ._query_results_format = query_results_format
615- return iterator
616612
617613 if "dryRun" not in request_body :
618614 callback (
@@ -706,6 +702,7 @@ def _wait_or_cancel(
706702 page_size : Optional [int ],
707703 max_results : Optional [int ],
708704 * ,
705+ query_results_format : Optional [str ] = None ,
709706 callback : Callable = lambda _ : None ,
710707) -> table .RowIterator :
711708 """Wait for a job to complete and return the results.
@@ -750,6 +747,7 @@ def _wait_or_cancel(
750747 ended = job .ended ,
751748 )
752749 )
750+ query_results ._query_results_format = query_results_format
753751 return query_results
754752 except Exception :
755753 # Attempt to cancel the job since we can't return the results.
0 commit comments