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

feat(storage): add arguments for *GenerationMatch uploading options #111

Merged
merged 7 commits into from Apr 22, 2020

Conversation

IlyaFaer
Copy link

These changes were originally made in another PR. Here is the version with changes requested by reviews.
Closes #16

@IlyaFaer IlyaFaer added api: storage Issues related to the googleapis/python-storage API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Apr 21, 2020
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 21, 2020
@frankyn frankyn requested review from crwilcox, tseaver and frankyn and removed request for tseaver April 21, 2020 17:52
@IlyaFaer IlyaFaer marked this pull request as ready for review April 21, 2020 17:54
Copy link
Member

@frankyn frankyn left a comment

Choose a reason for hiding this comment

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

Documentation nit.

google/cloud/storage/blob.py Outdated Show resolved Hide resolved
Copy link
Member

@frankyn frankyn left a comment

Choose a reason for hiding this comment

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

LGTM, ty!

@frankyn frankyn merged commit b11aa5f into googleapis:master Apr 22, 2020
@IlyaFaer IlyaFaer deleted the if_generation_match branch April 23, 2020 07:38
@1fish2
Copy link

1fish2 commented Apr 27, 2020

👍 Thanks to @HollayHorvath and @frankyn!

The code to create a directory placeholder changes from

blob = bucket.blob(name)
if not blob.exists():
    blob.upload_from_string(b'', content_type=OCTET_STREAM)

to

blob = bucket.blob(name)
try:
    blob.upload_from_string(
        b'', content_type=OCTET_STREAM, if_generation_match=0)
except PreconditionFailed:
    pass

because, as the doc says, "Setting to 0 makes the operation succeed only if there are no live versions of the blob."

In a handful of timings, the new code saved more than half the didn't-exist time and a bit of the already-exists time (although that might be measurement noise).

cojenco pushed a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
…oogleapis#111)

* feat(storage): add arguments for *GenerationMatch uploading options

* add unit tests changes

* change args names in unit tests

* add unit tests for _do_multipart_upload()

* add unit tests for _initiate_resumable_upload()

* add args translation into unit tests urls

* update args docs
cojenco pushed a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
…oogleapis#111)

* feat(storage): add arguments for *GenerationMatch uploading options

* add unit tests changes

* change args names in unit tests

* add unit tests for _do_multipart_upload()

* add unit tests for _initiate_resumable_upload()

* add args translation into unit tests urls

* update args docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/python-storage API. cla: yes This human has signed the Contributor License Agreement. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Storage: upload_from_string() with ifGenerationMatch=0
5 participants