Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1760e94

Browse files
authored
fix: relax timeout expectations (#1645)
* fix: relax timeout expectationsChanges to python-api-core can in certain cases cause timeout to berepresented as a literal python base object type. This CL adjustslogic that selects from multiple timeout values to better handle thiscase, which previously assumed either a None or scalar value beingpresent.Fixes:#1612* augment testing* blacken and lint fixes* unused import
1 parent3e021a4 commit1760e94

File tree

2 files changed

+102
-2
lines changed

2 files changed

+102
-2
lines changed

‎google/cloud/bigquery/client.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,7 +1895,10 @@ def _get_query_results(
18951895
extra_params:Dict[str,Any]= {"maxResults":0}
18961896

18971897
iftimeoutisnotNone:
1898-
timeout=max(timeout,_MIN_GET_QUERY_RESULTS_TIMEOUT)
1898+
iftype(timeout)==object:
1899+
timeout=_MIN_GET_QUERY_RESULTS_TIMEOUT
1900+
else:
1901+
timeout=max(timeout,_MIN_GET_QUERY_RESULTS_TIMEOUT)
18991902

19001903
ifprojectisNone:
19011904
project=self.project
@@ -3924,7 +3927,10 @@ def _list_rows_from_query_results(
39243927
}
39253928

39263929
iftimeoutisnotNone:
3927-
timeout=max(timeout,_MIN_GET_QUERY_RESULTS_TIMEOUT)
3930+
iftype(timeout)==object:
3931+
timeout=_MIN_GET_QUERY_RESULTS_TIMEOUT
3932+
else:
3933+
timeout=max(timeout,_MIN_GET_QUERY_RESULTS_TIMEOUT)
39283934

39293935
ifstart_indexisnotNone:
39303936
params["startIndex"]=start_index

‎tests/unit/test_client.py‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,31 @@ def test__get_query_results_miss_w_short_timeout(self):
395395
timeout=google.cloud.bigquery.client._MIN_GET_QUERY_RESULTS_TIMEOUT,
396396
)
397397

398+
deftest__get_query_results_miss_w_default_timeout(self):
399+
importgoogle.cloud.bigquery.client
400+
fromgoogle.cloud.exceptionsimportNotFound
401+
402+
creds=_make_credentials()
403+
client=self._make_one(self.PROJECT,creds)
404+
conn=client._connection=make_connection()
405+
path="/projects/other-project/queries/nothere"
406+
withself.assertRaises(NotFound):
407+
client._get_query_results(
408+
"nothere",
409+
None,
410+
project="other-project",
411+
location=self.LOCATION,
412+
timeout_ms=500,
413+
timeout=object(),# the api core default timeout
414+
)
415+
416+
conn.api_request.assert_called_once_with(
417+
method="GET",
418+
path=path,
419+
query_params={"maxResults":0,"timeoutMs":500,"location":self.LOCATION},
420+
timeout=google.cloud.bigquery.client._MIN_GET_QUERY_RESULTS_TIMEOUT,
421+
)
422+
398423
deftest__get_query_results_miss_w_client_location(self):
399424
fromgoogle.cloud.exceptionsimportNotFound
400425

@@ -438,6 +463,75 @@ def test__get_query_results_hit(self):
438463
self.assertEqual(query_results.total_rows,10)
439464
self.assertTrue(query_results.complete)
440465

466+
deftest__list_rows_from_query_results_w_none_timeout(self):
467+
fromgoogle.cloud.exceptionsimportNotFound
468+
fromgoogle.cloud.bigquery.schemaimportSchemaField
469+
470+
creds=_make_credentials()
471+
client=self._make_one(self.PROJECT,creds)
472+
conn=client._connection=make_connection()
473+
path="/projects/project/queries/nothere"
474+
iterator=client._list_rows_from_query_results(
475+
"nothere",
476+
location=None,
477+
project="project",
478+
schema=[
479+
SchemaField("f1","STRING",mode="REQUIRED"),
480+
SchemaField("f2","INTEGER",mode="REQUIRED"),
481+
],
482+
timeout=None,
483+
)
484+
485+
# trigger the iterator to request data
486+
withself.assertRaises(NotFound):
487+
iterator._get_next_page_response()
488+
489+
conn.api_request.assert_called_once_with(
490+
method="GET",
491+
path=path,
492+
query_params={
493+
"fields":"jobReference,totalRows,pageToken,rows",
494+
"location":None,
495+
"formatOptions.useInt64Timestamp":True,
496+
},
497+
timeout=None,
498+
)
499+
500+
deftest__list_rows_from_query_results_w_default_timeout(self):
501+
importgoogle.cloud.bigquery.client
502+
fromgoogle.cloud.exceptionsimportNotFound
503+
fromgoogle.cloud.bigquery.schemaimportSchemaField
504+
505+
creds=_make_credentials()
506+
client=self._make_one(self.PROJECT,creds)
507+
conn=client._connection=make_connection()
508+
path="/projects/project/queries/nothere"
509+
iterator=client._list_rows_from_query_results(
510+
"nothere",
511+
location=None,
512+
project="project",
513+
schema=[
514+
SchemaField("f1","STRING",mode="REQUIRED"),
515+
SchemaField("f2","INTEGER",mode="REQUIRED"),
516+
],
517+
timeout=object(),
518+
)
519+
520+
# trigger the iterator to request data
521+
withself.assertRaises(NotFound):
522+
iterator._get_next_page_response()
523+
524+
conn.api_request.assert_called_once_with(
525+
method="GET",
526+
path=path,
527+
query_params={
528+
"fields":"jobReference,totalRows,pageToken,rows",
529+
"location":None,
530+
"formatOptions.useInt64Timestamp":True,
531+
},
532+
timeout=google.cloud.bigquery.client._MIN_GET_QUERY_RESULTS_TIMEOUT,
533+
)
534+
441535
deftest_default_query_job_config(self):
442536
fromgoogle.cloud.bigqueryimportQueryJobConfig
443537

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp