GeezerVison is showing github.com — fix: correctly transform query job timeout configuration and exceptions by tswast · Pull Request #492 · googleapis/python-bigquery-pandas
This repository was archived by the owner on Sep 2, 2026. It is now read-only.
Conversation
tswast
commented
Mar 2, 2022
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
- Ensure the tests and linter pass
- Code coverage does not decrease (if any source code was changed)
- Appropriate docs were updated (if necessary)
Fixes #479 🦕
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Hmmm... conda-3.7 failure is on the exact test I'm trying to fix.
Details
______________ TestReadGBQIntegration.test_timeout_configuration _______________
self = <system.test_gbq.TestReadGBQIntegration object at 0x7f151cbc4090>
project_id = '****************'
def test_timeout_configuration(self, project_id):
sql_statement = """
select count(*) from unnest(generate_array(1,1000000)), unnest(generate_array(1, 10000))
"""
configs = [
# pandas-gbq timeout configuration. Transformed to REST API compatible version.
{"query": {"useQueryCache": False, "timeoutMs": 1}},
# REST API job timeout. See:
# https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfiguration.FIELDS.job_timeout_ms
{"query": {"useQueryCache": False}, "jobTimeoutMs": 1},
]
for config in configs:
with pytest.raises(gbq.QueryTimeout):
gbq.read_gbq(
sql_statement,
project_id=project_id,
credentials=self.credentials,
> configuration=config,
)
tests/system/test_gbq.py:491:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pandas_gbq/gbq.py:905: in read_gbq
dtypes=dtypes,
pandas_gbq/gbq.py:464: in run_query
self.client.cancel_job(query_reply)
/opt/conda/lib/python3.7/site-packages/google/cloud/bigquery/client.py:1557: in cancel_job
retry, method="POST", path=path, query_params=extra_params, timeout=timeout
/opt/conda/lib/python3.7/site-packages/google/cloud/bigquery/client.py:578: in _call_api
return call()
/opt/conda/lib/python3.7/site-packages/google/api_core/retry.py:291: in retry_wrapped_func
on_error=on_error,
/opt/conda/lib/python3.7/site-packages/google/api_core/retry.py:189: in retry_target
return target()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <google.cloud.bigquery._http.Connection object at 0x7f138fa1df90>
method = 'POST'
path = '/projects/****************/jobs/<google.cloud.bigquery.job.QueryJob object at 0x7f138fa15050>/cancel'
query_params = {'projection': 'full'}, data = None, content_type = None
headers = None, api_base_url = None, api_version = None, expect_json = True
_target_object = None, timeout = None
def api_request(
self,
method,
path,
query_params=None,
data=None,
content_type=None,
headers=None,
api_base_url=None,
api_version=None,
expect_json=True,
_target_object=None,
timeout=_DEFAULT_TIMEOUT,
):
"""Make a request over the HTTP transport to the API.
You shouldn't need to use this method, but if you plan to
interact with the API using these primitives, this is the
correct one to use.
:type method: str
:param method: The HTTP method name (ie, ``GET``, ``POST``, etc).
Required.
:type path: str
:param path: The path to the resource (ie, ``'/b/bucket-name'``).
Required.
:type query_params: dict or list
:param query_params: A dictionary of keys and values (or list of
key-value pairs) to insert into the query
string of the URL.
:type data: str
:param data: The data to send as the body of the request. Default is
the empty string.
:type content_type: str
:param content_type: The proper MIME type of the data provided. Default
is None.
:type headers: dict
:param headers: extra HTTP headers to be sent with the request.
:type api_base_url: str
:param api_base_url: The base URL for the API endpoint.
Typically you won't have to provide this.
Default is the standard API base URL.
:type api_version: str
:param api_version: The version of the API to call. Typically
you shouldn't provide this and instead use
the default for the library. Default is the
latest API version supported by
google-cloud-python.
:type expect_json: bool
:param expect_json: If True, this method will try to parse the
response as JSON and raise an exception if
that cannot be done. Default is True.
:type _target_object: :class:`object`
:param _target_object:
(Optional) Protected argument to be used by library callers. This
can allow custom behavior, for example, to defer an HTTP request
and complete initialization of the object at a later time.
:type timeout: float or tuple
:param timeout: (optional) The amount of time, in seconds, to wait
for the server response.
Can also be passed as a tuple (connect_timeout, read_timeout).
See :meth:`requests.Session.request` documentation for details.
:raises ~google.cloud.exceptions.GoogleCloudError: if the response code
is not 200 OK.
:raises ValueError: if the response content type is not JSON.
:rtype: dict or str
:returns: The API response payload, either as a raw string or
a dictionary if the response is valid JSON.
"""
url = self.build_api_url(
path=path,
query_params=query_params,
api_base_url=api_base_url,
api_version=api_version,
)
# Making the executive decision that any dictionary
# data will be sent properly as JSON.
if data and isinstance(data, dict):
data = json.dumps(data)
content_type = "application/json"
response = self._make_request(
method=method,
url=url,
data=data,
content_type=content_type,
headers=headers,
target_object=_target_object,
timeout=timeout,
)
if not 200 <= response.status_code < 300:
> raise exceptions.from_http_response(response)
E google.api_core.exceptions.BadRequest: 400 POST https://bigquery.googleapis.com/bigquery/v2/projects/****************/jobs/%3Cgoogle.cloud.bigquery.job.QueryJob%20object%20at%200x7f138fa15050%3E/cancel?projection=full&prettyPrint=false: Invalid job ID "<google.cloud.bigquery.job.QueryJob object at 0x7f138fa15050>". Job IDs must be alphanumeric (plus underscores and dashes) and must be at most 1024 characters long.
/opt/conda/lib/python3.7/site-packages/google/cloud/_http.py:484: BadRequest
=============================== warnings summary ===============================
tests/system/test_gbq.py::TestReadGBQIntegration::test_array_length_zero
/opt/conda/lib/python3.7/site-packages/pandas/core/dtypes/missing.py:415: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
if left_value != right_value:
tests/system/test_gbq.py::TestToGBQIntegration::test_upload_data
/home/mambauser/project/tests/system/test_gbq.py:622: PendingDeprecationWarning: chunksize will be ignored when using api_method='load_csv' in a future version of pandas-gbq
credentials=self.credentials,
tests/system/test_gbq.py::TestToGBQIntegration::test_upload_data_if_table_exists_append
/home/mambauser/project/tests/system/test_gbq.py:706: PendingDeprecationWarning: chunksize will be ignored when using api_method='load_csv' in a future version of pandas-gbq
credentials=self.credentials,
tests/system/test_gbq.py::TestToGBQIntegration::test_upload_subset_columns_if_table_exists_append
/home/mambauser/project/tests/system/test_gbq.py:752: PendingDeprecationWarning: chunksize will be ignored when using api_method='load_csv' in a future version of pandas-gbq
credentials=self.credentials,
tests/system/test_gbq.py::TestToGBQIntegration::test_upload_data_if_table_exists_replace
/home/mambauser/project/tests/system/test_gbq.py:786: PendingDeprecationWarning: chunksize will be ignored when using api_method='load_csv' in a future version of pandas-gbq
credentials=self.credentials,
tests/system/test_gbq.py::TestToGBQIntegration::test_upload_data_flexible_column_order
/home/mambauser/project/tests/system/test_gbq.py:915: PendingDeprecationWarning: chunksize will be ignored when using api_method='load_csv' in a future version of pandas-gbq
credentials=self.credentials,
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
---------- coverage: platform linux, python 3.7.12-final-0 -----------
Coverage XML written to file /tmp/pytest-cov.xml
=========================== short test summary info ============================
FAILED tests/system/test_gbq.py::TestReadGBQIntegration::test_timeout_configuration
======= 1 failed, 262 passed, 9 skipped, 6 warnings in 301.91s (0:05:01) =======
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
tswast
commented
Mar 4, 2022
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
Oh! Possible bug in google-cloud-bigquery. I think cancel_job might not be extracting the job ID and location correctly from a QueryJob.
Edit: That session uses google-cloud-bigquery==1.27.2. Accept job as argument wasn't added until googleapis/python-bigquery#617 in 2.14.0.
TODO:
- Fix logic to send job ID and location instead of QueryJob to
cancel_job
- Add unit test covering client-side timeout and cancellation
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…leapis/python-bigquery-pandas into issue479-test_timeout_configuration
…leapis/python-bigquery-pandas into issue479-test_timeout_configuration
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
parthea
pushed a commit
to googleapis/google-cloud-python
that referenced
this pull request
Sep 18, 2025
Reviewers
steffnay
Awaiting requested review from steffnay
2 more reviewers
parthea
parthea approved these changes
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
api: bigquery
Issues related to the googleapis/python-bigquery-pandas API.
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|