GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@tswast tswast commented Mar 2, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

All reactions
@tswast
fix: correctly transform query job timeout configuration and exceptions
862e9f3
@product-auto-label product-auto-label Bot added the api: bigquery Issues related to the googleapis/python-bigquery-pandas API. label Mar 2, 2022
tswast added 2 commits March 3, 2022 17:04
@tswast
unit tests for configuration transformations
80a7e6e
@tswast
Merge branch 'main' into issue479-test_timeout_configuration
ef5bf37
@tswast
tswast marked this pull request as ready for review March 3, 2022 23:05
@tswast
tswast requested review from a team and steffnay March 3, 2022 23:05
@tswast tswast added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 4, 2022
@tswast

tswast commented Mar 4, 2022

Copy link
Copy Markdown
Contributor Author

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) =======
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tswast tswast added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Mar 4, 2022
@tswast

tswast commented Mar 4, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 4, 2022
tswast and others added 10 commits March 4, 2022 15:20
@tswast
add unit tests for timeout
e15de6d
@tswast
Merge remote-tracking branch 'upstream/main' into issue479-test_timeo…
ef3977c
…ut_configuration
@tswast
link todo to relevant issue
c39eff9
@gcf-owl-bot
🦉 Updates from OwlBot post-processor
854c0cb
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
@gcf-owl-bot
Merge branch 'issue479-test_timeout_configuration' of https://github.…
df74123
…com/googleapis/python-bigquery-pandas into issue479-test_timeout_configuration
@tswast
use correct template for freezegun deps
0c76e87
@tswast
Merge branch 'issue479-test_timeout_configuration' of github.com:goog…
68a19af
…leapis/python-bigquery-pandas into issue479-test_timeout_configuration
@gcf-owl-bot
🦉 Updates from OwlBot post-processor
84f1024
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
@tswast
decrease tick time in case multiple time calls are made
078db47
@tswast
Merge branch 'issue479-test_timeout_configuration' of github.com:goog…
5d076f9
…leapis/python-bigquery-pandas into issue479-test_timeout_configuration
@tswast tswast removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Mar 4, 2022
tswast added 4 commits March 4, 2022 16:27
@tswast
try no tick
fd06ba5
@tswast
add freezegun to conda deps
c820d32
@tswast
Merge branch 'main' into issue479-test_timeout_configuration
3d379b6
@tswast
Merge branch 'main' into issue479-test_timeout_configuration
efe7605
busunkim96
busunkim96 approved these changes Mar 8, 2022
View reviewed changes
Comment thread pandas_gbq/gbq.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

parthea
parthea approved these changes Mar 8, 2022
View reviewed changes
Comment thread tests/unit/test_gbq.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

tswast and others added 2 commits March 8, 2022 10:50
@tswast @busunkim96
typo
32cd3e8
Co-authored-by: Bu Sun Kim <[email protected]>
@tswast @parthea
typo
7bdf7d8
Co-authored-by: Anthonios Partheniou <[email protected]>
@tswast
tswast merged commit d8c3900 into main Mar 8, 2022
@tswast
tswast deleted the issue479-test_timeout_configuration branch March 8, 2022 19:53
@release-please release-please Bot mentioned this pull request Mar 8, 2022
chore(main): release 0.17.4 #499
Merged
gcf-merge-on-green Bot pushed a commit that referenced this pull request Mar 14, 2022
@release-please
chore(main): release 0.17.4 (#499)
ae6ad6b
🤖 I have created a release *beep* *boop*
---


### [0.17.4](v0.17.3...v0.17.4) (2022-03-14)


### Bug Fixes

* avoid deprecated "out-of-band" authentication flow ([#500](#500)) ([4758e3a](4758e3a))
* correctly transform query job timeout configuration and exceptions ([#492](#492)) ([d8c3900](d8c3900))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
parthea pushed a commit to googleapis/google-cloud-python that referenced this pull request Sep 18, 2025
@release-please
chore(main): release 0.17.4 (#499)
a718cbf
🤖 I have created a release *beep* *boop*
---


### [0.17.4](googleapis/python-bigquery-pandas@v0.17.3...v0.17.4) (2022-03-14)


### Bug Fixes

* avoid deprecated "out-of-band" authentication flow ([#500](googleapis/python-bigquery-pandas#500)) ([4758e3a](googleapis/python-bigquery-pandas@4758e3a))
* correctly transform query job timeout configuration and exceptions ([#492](googleapis/python-bigquery-pandas#492)) ([d8c3900](googleapis/python-bigquery-pandas@d8c3900))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@steffnay steffnay Awaiting requested review from steffnay
2 more reviewers
@parthea parthea parthea approved these changes
@busunkim96 busunkim96 busunkim96 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.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

tests.system.test_gbq.TestReadGBQIntegration: test_timeout_configuration failed

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@tswast @parthea @busunkim96 @yoshi-kokoro
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.