Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid default value for timeout in PollingFuture #523

Open
TMo484 opened this issue Aug 25, 2023 · 1 comment · May be fixed by TMo484/python-api-core#1
Open

Invalid default value for timeout in PollingFuture #523

TMo484 opened this issue Aug 25, 2023 · 1 comment · May be fixed by TMo484/python-api-core#1

Comments

@TMo484
Copy link

TMo484 commented Aug 25, 2023

There is a bug in the initialization of timeout inside the PollingFuture class, where the default value passed into various methods is of type object when it is expected to be an int, float, or None.

The below example uses the bigquery client to generate and execute an Operation, and then demonstrates the raised error when attempting to access the .exception method.

Environment Details
Windows 10
Python 3.9.5
pip 21.1.1
pip packages:
google-cloud-bigquery==3.11.4
google-api-core==2.11.1

Steps to reproduce

  1. python -m venv google_api_test
  2. google_api_test\scripts\pip install google-cloud-bigquery google-api-core

Code Example

from google.cloud import bigquery
client = bigquery.client.Client()

job = client.query(
        """
        SELECT
          CONCAT(
            'https://stackoverflow.com/questions/',
            CAST(id as STRING)) as url,
          view_count
        FROM `bigquery-public-data.stackoverflow.posts_questions`
        WHERE tags like '%google-bigquery%'
        ORDER BY RAND() DESC"""
    )

job.exception()

Stack Trace

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "{WINDOWS_ROOT}\google_api_test\lib\site-packages\google\api_core\future\polling.py", line 282, in exception
    self._blocking_poll(timeout=timeout)
  File "{WINDOWS_ROOT}\google_api_test\lib\site-packages\google\cloud\bigquery\job\query.py", line 1257, in _blocking_poll
    super(QueryJob, self)._blocking_poll(timeout=timeout, **kwargs)
  File "{WINDOWS_ROOT}\google_api_test\lib\site-packages\google\api_core\future\polling.py", line 137, in _blocking_poll
    polling(self._done_or_raise)(retry=retry)
  File "{WINDOWS_ROOT}\google_api_test\lib\site-packages\google\api_core\retry.py", line 349, in retry_wrapped_func
    return retry_target(
  File "{WINDOWS_ROOT}\google_api_test\lib\site-packages\google\api_core\retry.py", line 191, in retry_target
    return target()
  File "{WINDOWS_ROOT}\google_api_test\lib\site-packages\google\cloud\bigquery\job\query.py", line 1379, in _done_or_raise
    self._reload_query_results(retry=retry, timeout=transport_timeout)
  File "{WINDOWS_ROOT}\google_api_test\lib\site-packages\google\cloud\bigquery\job\query.py", line 1360, in _reload_query_results
    self._query_results = self._client._get_query_results(
  File "{WINDOWS_ROOT}\google_api_test\lib\site-packages\google\cloud\bigquery\client.py", line 1898, in _get_query_results
    timeout = max(timeout, _MIN_GET_QUERY_RESULTS_TIMEOUT)
TypeError: '>' not supported between instances of 'int' and 'object'

Side Note:
This example does not directly demonstrate the error effect on the job.result() function as, in this example through BigQuery, the PollingFuture.result method is wrapped in QueryJob.result (link to class). This wrapper overrides the invalid timeout with an acceptable timeout value of None (link to argument)

@TMo484 TMo484 linked a pull request Aug 25, 2023 that will close this issue
4 tasks
@vchudnov-g
Copy link
Contributor

Thanks for reporting this and suggesting a fix (TMo484#1). We will review this as soon as can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants