Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

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

Merged
frankyn merged 7 commits into
googleapis:masterfrom
MaxxleLLC:if_generation_match
Apr 22, 2020
Merged

feat(storage): add arguments for *GenerationMatch uploading options#111
frankyn merged 7 commits into
googleapis:masterfrom
MaxxleLLC:if_generation_match

Conversation

@IlyaFaer

Copy link
Copy Markdown

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

@IlyaFaerIlyaFaer 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
@googlebotgooglebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 21, 2020
@frankyn
frankyn requested review from crwilcox, frankyn and tseaver and removed request for tseaverApril 21, 2020 17:52
@IlyaFaer
IlyaFaer marked this pull request as ready for review April 21, 2020 17:54

@frankynfrankyn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Documentation nit.

Comment threadgoogle/cloud/storage/blob.py Outdated

@frankynfrankyn left a comment

Copy link
Copy Markdown
Contributor

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:masterApr 22, 2020
@IlyaFaer
IlyaFaer deleted the if_generation_match branch April 23, 2020 07:38
@1fish2

Copy link
Copy Markdown

👍 Thanks to @HollayHorvath and @frankyn!

The code to create a directory placeholder changes from

blob=bucket.blob(name)
ifnotblob.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)
exceptPreconditionFailed:
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
@release-pleaserelease-pleaseBot mentioned this pull request Jan 12, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: storageIssues related to the googleapis/python-storage API.cla: yesThis 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

@IlyaFaer@1fish2@crwilcox@frankyn@googlebot