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: apply timeout to all resumable upload requests by plamut · Pull Request #1070 · googleapis/python-bigquery

This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Conversation

@plamut

@plamut plamut commented Nov 18, 2021

Copy link
Copy Markdown
Contributor

Fixes #1067.

PR checklist:

  • 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)

Sorry, something went wrong.

Uh oh!

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

All reactions
@plamut
fix: apply timeout to all resumable upload requests
76a7ad0
@plamut
plamut requested review from a team and tswast November 18, 2021 10:20
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 18, 2021
@product-auto-label product-auto-label Bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Nov 18, 2021
tseaver
tseaver reviewed Nov 18, 2021
View reviewed changes
Comment thread google/cloud/bigquery/client.py Resolved

Uh oh!

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

@tswast

tswast commented Nov 18, 2021

Copy link
Copy Markdown
Contributor

Test failure:

____________________________ test_upload_chunksize _____________________________

client = <google.cloud.bigquery.client.Client object at 0x7f73ab1c0710>

    def test_upload_chunksize(client):
        with mock.patch("google.cloud.bigquery.client.ResumableUpload") as RU:
            upload = RU.return_value

            upload.finished = False

            def transmit_next_chunk(transport):
                upload.finished = True
                result = mock.MagicMock()
                result.json.return_value = {}
                return result

            upload.transmit_next_chunk = transmit_next_chunk
            f = io.BytesIO()
>           client.load_table_from_file(f, "foo.bar")

tests/unit/test_client.py:8469:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
google/cloud/bigquery/client.py:2443: in load_table_from_file
    file_obj, job_resource, num_retries, timeout, project=project
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <google.cloud.bigquery.client.Client object at 0x7f73ab1c0710>
stream = <_io.BytesIO object at 0x7f73ab14f048>
metadata = {'configuration': {'load': {'destinationTable': {'datasetId': 'foo', 'projectId': 'PROJECT', 'tableId': 'bar'}}}, 'jobReference': {'jobId': 'c2ad6c61-6202-4c0e-a6af-8310c4aabd61', 'projectId': 'PROJECT'}}
num_retries = 6, timeout = None, project = 'PROJECT'

    def _do_resumable_upload(
        self, stream, metadata, num_retries, timeout, project=None
    ):
        """Perform a resumable upload.

        Args:
            stream (IO[bytes]): A bytes IO object open for reading.

            metadata (Dict): The metadata associated with the upload.

            num_retries (int):
                Number of upload retries. (Deprecated: This
                argument will be removed in a future release.)

            timeout (float):
                The number of seconds to wait for the underlying HTTP transport
                before using ``retry``.

            project (Optional[str]):
                Project ID of the project of where to run the upload. Defaults
                to the client's project.

        Returns:
            requests.Response:
                The "200 OK" response object returned after the final chunk
                is uploaded.
        """
        upload, transport = self._initiate_resumable_upload(
            stream, metadata, num_retries, timeout, project=project
        )

        while not upload.finished:
>           response = upload.transmit_next_chunk(transport, timeout=timeout)
E           TypeError: transmit_next_chunk() got an unexpected keyword argument 'timeout'

google/cloud/bigquery/client.py:2853: TypeError
=============================== warnings summary ===============================

I think we'll have to bump the minimum version of the resumable media library.

All reactions

Sorry, something went wrong.

Uh oh!

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

@tseaver

tseaver commented Nov 18, 2021

Copy link
Copy Markdown
Contributor

@tswast The feature was added (by @plamut) in June 2020, and released with version 0.6.0 of google-resumable-media, which is our minimum version.

The test failure comes from the broken stub version in the testcase.

tswast reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

plamut and others added 3 commits November 20, 2021 15:06
@plamut
Merge branch 'main' into iss-1067
10062dc
@plamut
Fix stub in test case
59af040
@plamut
Improve timeout type and other type annotations
53fd25f
tswast
tswast reviewed Nov 22, 2021
View reviewed changes
Comment thread google/cloud/bigquery/client.py
may be repeated several times using the same timeout each time.

Can also be passed as a tuple (connect_timeout, read_timeout).
See :meth:`requests.Session.request` documentation for details.

@tswast tswast Nov 22, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious, does the same apply to our other API requests? I know we use requests library for those too, but via google-cloud-core.

Sorry, something went wrong.

Uh oh!

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

All reactions

@plamut plamut Nov 22, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can see, it does. The timeout argument gets passed down to google.cloud._http.JSONConnection, which accepts a two-tuple.

I think we did not advertise this second option in BigQuery and just went with Optional[Union[int, float]] to avoid leaking transport implementation details, but I'm not 100%.

Sorry, something went wrong.

Uh oh!

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

All reactions

@tseaver tseaver Nov 22, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

google-cloud-core definitely exposes both float and tuple for timeout.

Note that its current docs link (under cloud.google.com) doesn't show those details.

Sorry, something went wrong.

Uh oh!

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

All reactions
tswast
tswast reviewed Nov 22, 2021
View reviewed changes
Comment thread google/cloud/bigquery/client.py Resolved

Uh oh!

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

@plamut
Annnotate return type of _do_resumable_upload()
4d9460c
tswast
tswast approved these changes Nov 23, 2021
View reviewed changes
@plamut
plamut merged commit 3314dfb into googleapis:main Nov 24, 2021
@plamut
plamut deleted the iss-1067 branch November 24, 2021 15:12
@release-please release-please Bot mentioned this pull request Jan 4, 2022
chore(main): release python-bigquery 1.27.1 #1097
Closed
abdelmegahedgoogle pushed a commit to abdelmegahedgoogle/python-bigquery that referenced this pull request Apr 17, 2023
@plamut @abdelmegahedgoogle
fix: apply timeout to all resumable upload requests (googleapis#1070)
7a7770f
* fix: apply timeout to all resumable upload requests

* Fix stub in test case

* Improve timeout type and other type annotations

* Annnotate return type of _do_resumable_upload()
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

2 more reviewers
@tseaver tseaver tseaver left review comments
@tswast tswast tswast 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 API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Provided timeout should be applied to all resumable upload requests

Uh oh!

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

3 participants

@plamut @tswast @tseaver
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.