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 — added support for generation-based query and delete of blobs. by tsinha · Pull Request #1435 · googleapis/google-cloud-python

Conversation

@tsinha

@tsinha tsinha commented Feb 1, 2016

Copy link
Copy Markdown

Small modifications to get_blob and delete_blob to handle generation ids when querying buckets that have versioning enabled.

Sorry, something went wrong.

Uh oh!

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

tillahoffmann and mtmtcode reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@tsinha
added support for generation-based query and delete of blobs.
c3c9a7a
@googlebot

googlebot commented Feb 1, 2016

Copy link
Copy Markdown

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.
All reactions

Sorry, something went wrong.

Uh oh!

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

@googlebot googlebot added the cla: no This human has *not* signed the Contributor License Agreement. label Feb 1, 2016
tsinha added 2 commits January 31, 2016 21:00
@tsinha
added support for generation-based query and delete of blobs.
35cf688
@tsinha
Merge branch 'master' of github.com:VitalLabs/gcloud-python
1af1e97
@tsinha

tsinha commented Feb 1, 2016

Copy link
Copy Markdown
Author

I signed the CLA as Vital Labs, Inc.

All reactions

Sorry, something went wrong.

Uh oh!

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

tsinha added 3 commits January 31, 2016 21:14
@tsinha
cleaned up to past lint.
016080a
@tsinha
cleaned up to pass lint.
299fab9
@tsinha
Merge branch 'master' of github.com:VitalLabs/gcloud-python
5d8d041
dhermes
dhermes reviewed Feb 1, 2016
View reviewed changes
Comment thread gcloud/storage/bucket.py Outdated

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

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

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

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

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

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

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

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

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

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

@dhermes

dhermes commented Feb 1, 2016

Copy link
Copy Markdown
Contributor

@tsinha You can ignore the AppVeyor failure for test_upload_from_file_w_bound_client_multipart, we are tracking it on #1434.

Updating Bucket.delete_blob and Bucket.get_blob is insufficient here, Blob.delete and Blob.exists and Blob.reload may also need updating (or you may get that for free when updating Blob.path)

@jgeewax What should be done about matching his signature of the CLA with his GitHub handle?

All reactions

Sorry, something went wrong.

Uh oh!

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

@tsinha

tsinha commented Feb 1, 2016

Copy link
Copy Markdown
Author

I'll look at the blob level methods and make sure everything works with the bucket level query, or refactor as you suggested if needed.

I'll post an update shortly.

All reactions

Sorry, something went wrong.

Uh oh!

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

@googlebot

googlebot commented Feb 1, 2016

Copy link
Copy Markdown

CLAs look good, thanks!

All reactions

Sorry, something went wrong.

Uh oh!

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

@googlebot googlebot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Feb 1, 2016
tsinha added 2 commits February 1, 2016 16:14
@tsinha
using 'client.connection.api_request' instead of manually creating AP…
e1e02da
…I paths. added generation support to blob.delete and blob.exists.
@tsinha
ignoring placeholder generation parameter in the mock delete_blob fun…
3aa1185
…ction
@tsinha

tsinha commented Feb 2, 2016

Copy link
Copy Markdown
Author

@dhermes I looked over and fixed blob.exists and blob.delete.

Still unsure about adding generation param directly into blob.path

It doesn't seem as clean as having the api_request create the appropriate paths via blob.path and query_params at the bucket level.

Otherwise, I think this PR should be ready to go.

All reactions

Sorry, something went wrong.

Uh oh!

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

@dhermes

dhermes commented Feb 3, 2016

Copy link
Copy Markdown
Contributor

@tsinha the generation is required to be in the path, since it uniquely defines the object if specified.

Bucket.delete_blob and Bucket.get_blob are meant to be "dumb" (i.e. they don't know how to do much) and the knowledge of how to make the request should live on Blob.

All reactions

Sorry, something went wrong.

Uh oh!

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

tsinha added 4 commits February 3, 2016 11:57
@tsinha
target_object parameter fix.
70a4f4c
@tsinha
query_params are default empty if generation is None.
9cc73fd
@tsinha
added tests for None generations
ed94125
@tsinha
working on support for version sensitive renaming of blobs.
8d92cf5
@tsinha

tsinha commented Feb 3, 2016

Copy link
Copy Markdown
Author

@dhermes Thanks for the feedback.

Can you help me brainstorm how to reconcile the way in which api_requests are made with embedding the generation query parameter at the blob level?

This confounds my current WIP, which will enable the renaming of blobs while preserving versions, since the 'copyTo' API end-point requires another query param ('sourceGeneration') to copy the right version.

If we move generation into blob.path, I'd end up with something like the following:

https://www.googleapis.com/storage/v1/b/sourceBucket/o/sourceObject?generation=XXX/copyTo/b/destinationBucket/o/destinationObject?sourceGeneration=XXX

But I may not be thinking it through completely... any advice you have would be helpful.

All reactions

Sorry, something went wrong.

Uh oh!

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

@dhermes

dhermes commented Feb 3, 2016

Copy link
Copy Markdown
Contributor

I think you've just thought about it more than I had 😀

However, I'd still rather special case Bucket.copy_blob than special case every other place a generation might be used.

You could also leave Blob.path as-is and we could have another property that also contains identifying informating in query params, like Blob.path_with_params (or a name that is less hideous).

All reactions

Sorry, something went wrong.

Uh oh!

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

@tsinha
working version with a new path_with_params function at the blob leve…
3bfdd10
…l to help with generation based queries of blobs. also added version-based blob copying and renaming. fixed a typo in _helpers.py.
@tsinha

tsinha commented Feb 4, 2016

Copy link
Copy Markdown
Author

@dhermes I've added a new blob.path_with_params function to alleviate some of the checking at the bucket level: here and here.

I've also got a working version of the copy_blob and rename_blob functions with versioning support here and here.

I changed the API for copy_blob a little to fit into the existing rename_blob logic... that is, if versioned copy is enabled, copy_blob returns a tuple of two lists that contain the old and new blobs... rename_blobs takes the old_blobs list from this tuple and deletes them, and then returns the new_blobs list.

If versioning is not enabled, then copy_blobs's return parameters are unchanged from the existing API.

What do you think about this approach? I can add testing around this if it looks reasonable.

All reactions

Sorry, something went wrong.

Uh oh!

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

@dhermes

dhermes commented Feb 5, 2016

Copy link
Copy Markdown
Contributor

@tsinha Sorry for the review delay. I'm traveling and won't have a chance to look at this until next Monday. (I feel bad, sorry for the negative experience.)

All reactions

Sorry, something went wrong.

Uh oh!

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

@tsinha

tsinha commented Feb 5, 2016

Copy link
Copy Markdown
Author

No worries... I look forward to your feedback next week. Safe travels.

All reactions

Sorry, something went wrong.

Uh oh!

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

dhermes
dhermes reviewed Feb 15, 2016
View reviewed changes
Comment thread gcloud/storage/blob.py
params = {}
if self.generation is not None:
params = {'generation': self.generation}

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

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

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

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

@tsinha

tsinha commented Feb 29, 2016

Copy link
Copy Markdown
Author

@dhermes I have not forgotten about this. Tied up with some other stuff and will get back to this ASAP.

All reactions

Sorry, something went wrong.

Uh oh!

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

@dhermes

dhermes commented Feb 29, 2016

Copy link
Copy Markdown
Contributor

Thanks for the update

All reactions

Sorry, something went wrong.

Uh oh!

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

@tsinha
fixed conflict
5d491ee
@tseaver tseaver added the api: storage Issues related to the Cloud Storage API. label Mar 15, 2017
@lukesneeringer lukesneeringer added the priority: p2 Moderately-important priority. Fix may not be included in next release. label Apr 19, 2017
@tillahoffmann

tillahoffmann commented Jun 30, 2017 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

@dhermes, @tsinha, thanks for looking into this. Do you have any updates on when this PR might get merged to address #2463?

All reactions

Sorry, something went wrong.

Uh oh!

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

@dhermes

dhermes commented Jun 30, 2017

Copy link
Copy Markdown
Contributor

@tillahoffmann There have been lots of changes to blob since this PR was originally sent. Some code paths in the current release (google-cloud-storage==1.2.0) will "just work" for this feature.

Peeking at the code, at least the Blob.download_* functions will incorporate the generation (but, as a hack, only if media_link isn't set on the Blob instance). As for delete, it calls out to Blob.path_helper which does not incorporate the generation.

All reactions

Sorry, something went wrong.

Uh oh!

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

@tillahoffmann

tillahoffmann commented Jul 1, 2017

Copy link
Copy Markdown
Contributor

@dhermes, thanks for the update. Do you have any recommendations on how to access md5 and crc32c hashes given a generation number from python?

All reactions

Sorry, something went wrong.

Uh oh!

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

@dhermes

dhermes commented Jul 1, 2017

Copy link
Copy Markdown
Contributor

Sure thing. Here is a somewhat icky hack (but it'll work for now).

For a file with multiple versions:

$ gsutil ls -a gs://some-bucket
gs://some-bucket/file.txt#1498874876972049
gs://some-bucket/file.txt#1498875135704497

If you reload() it like normal, you'll see the latest version:

>>> from google.cloud import storage
>>>
>>> client = storage.Client()
>>> bucket = client.bucket('some-bucket')
>>> blob_normal = bucket.blob('file.txt')
>>> blob_normal.reload()
>>> blob_normal._properties
{u'bucket': u'some-bucket',
 u'contentType': u'text/plain',
 u'crc32c': u'JcxYOQ==',
 u'etag': u'CLH7moCB59QCEAE=',
 u'generation': u'1498875135704497',
 u'id': u'some-bucket/file.txt/1498875135704497',
 u'kind': u'storage#object',
 u'md5Hash': u'F/IyVDfyzIWJW12F0xO6+Q==',
 u'mediaLink': u'https://www.googleapis.com/download/storage/v1/b/some-bucket/o/file.txt?generation=1498875135704497&alt=media',
 u'metageneration': u'1',
 u'name': u'file.txt',
 u'selfLink': u'https://www.googleapis.com/storage/v1/b/some-bucket/o/file.txt',
 u'size': u'1672',
 u'storageClass': u'MULTI_REGIONAL',
 u'timeCreated': u'2017-07-01T02:12:15.663Z',
 u'timeStorageClassUpdated': u'2017-07-01T02:12:15.663Z',
 u'updated': u'2017-07-01T02:12:15.663Z'}

However, if you manually patch reload on the object, you can get the data you want:

>>> from google.cloud.storage.blob import _quote
>>>
>>> GENERATION = '1498874876972049'
>>>
>>> def reload(self, client=None):
...     client = self._require_client(client)
...     query_params = {'projection': 'noAcl', 'generation': GENERATION}
...     api_response = client._connection.api_request(
...         method='GET', path=self.path, query_params=query_params,
...         _target_object=self)
...     self._set_properties(api_response)
...
>>>
>>> blob_patched = bucket.blob('file.txt')
>>> blob_patched.reload = reload.__get__(blob_patched)
>>> blob_patched._properties
{u'bucket': u'some-bucket',
 u'contentType': u'text/plain',
 u'crc32c': u'MO9tZQ==',
 u'etag': u'CJGY64SA59QCEAE=',
 u'generation': u'1498874876972049',
 u'id': u'some-bucket/file.txt/1498874876972049',
 u'kind': u'storage#object',
 u'md5Hash': u'zPc9wCyNcKGiYV3ijiB2iw==',
 u'mediaLink': u'https://www.googleapis.com/download/storage/v1/b/some-bucket/o/file.txt?generation=1498874876972049&alt=media',
 u'metageneration': u'1',
 u'name': u'file.txt',
 u'selfLink': u'https://www.googleapis.com/storage/v1/b/some-bucket/o/file.txt',
 u'size': u'1635',
 u'storageClass': u'MULTI_REGIONAL',
 u'timeCreated': u'2017-07-01T02:07:56.965Z',
 u'timeDeleted': u'2017-07-01T02:12:15.704Z',
 u'timeStorageClassUpdated': u'2017-07-01T02:07:56.965Z',
 u'updated': u'2017-07-01T02:07:56.965Z'}
All reactions

Sorry, something went wrong.

Uh oh!

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

@lukesneeringer

lukesneeringer commented Aug 7, 2017 •
edited by dhermes
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Hi @tillahoffmann @tsinha,
Since the code has changed so much since your original PR, and it sounds like there is an existing path to do what you need now, I am going to close this. I am sorry that we sat on it for so long.

If there are any outstanding issues remaining, feel free to re-open (or open a new issue).

All reactions

Sorry, something went wrong.

Uh oh!

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

@lukesneeringer lukesneeringer closed this Aug 7, 2017
parthea pushed a commit that referenced this pull request Sep 22, 2023
@dizcology @danoscarmike
[DO NOT MERGE] remove face detection samples [(#1435)](GoogleCloudPla…
e97a931
…tform/python-docs-samples#1435)

* remove face detection samples

* update docstring

* linter

* linter
parthea pushed a commit that referenced this pull request Nov 24, 2025
@release-please
chore(main): release 1.4.0 (#1435)
409c90d
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
parthea added a commit that referenced this pull request Mar 6, 2026
@tswast @parthea
deps: remove upper bound on packaging dependency (#1440)
03e4059
* deps: remove upper bound on packaging dependency

Towards #1435

* install prerelease version of packaging

* bump minimum packaging version

Co-authored-by: Anthonios Partheniou <[email protected]>
parthea pushed a commit that referenced this pull request Mar 9, 2026
@release-please
chore(main): release 3.1.0 (#1435)
cf1cbeb
🤖 I have created a release *beep* *boop*
---


## [3.1.0](https://togithub.com/googleapis/python-storage/compare/v3.0.0...v3.1.0) (2025-02-27)


### Features

* Add api_key argument to Client constructor ([#1441](https://togithub.com/googleapis/python-storage/issues/1441)) ([c869e15](https://togithub.com/googleapis/python-storage/commit/c869e15ec535a0aa50029d30b6a3ce64ff119b5f))
* Add Bucket.move_blob() for HNS-enabled buckets ([#1431](https://togithub.com/googleapis/python-storage/issues/1431)) ([24c000f](https://togithub.com/googleapis/python-storage/commit/24c000fb7b9f576e6d6c6ec5733f3971fe133655))

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

Reviewers

No reviews

Uh oh!

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

Assignees

No one assigned

Labels

api: storage Issues related to the Cloud Storage API. cla: yes This human has signed the Contributor License Agreement. priority: p2 Moderately-important priority. Fix may not be included in next release.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

6 participants

@tsinha @googlebot @dhermes @tillahoffmann @lukesneeringer @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.