Repository navigation
feat(storage): add object contexts samples - #14668
sahusneha2004 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces new sample snippets and corresponding integration tests for managing Google Cloud Storage object contexts, including setting, getting, listing, and deleting custom contexts. The review feedback highlights critical safety improvements across these snippets, specifically pointing out potential AttributeError exceptions if the requested blob does not exist (returning None) or if blob.contexts is uninitialized when attempting to set custom contexts.
Add samples for setting, getting, listing (filter) and deleting GCS object contexts. Region tags: storage_set_object_contexts, storage_get_object_contexts, storage_list_object_contexts, storage_delete_object_contexts. Internal bug: b/482946642 [Generated-by: AI]
Switch the set/get/delete object-contexts samples from `bucket.get_blob()` (which returns None for a missing object) to `bucket.blob()` + `blob.reload()`, the idiom used by the other precondition-based samples in this directory, so a missing object raises `google.api_core.exceptions.NotFound` instead of an AttributeError. Drop the redundant `if blob.contexts` guard in the get sample: `Blob.contexts` always returns an `ObjectContexts` instance. Internal bug: b/482946642 [Generated-by: AI]
630cbcf to
153ef0d
Compare
|
Here is the summary of changes. You are about to add 4 region tags.
This comment is generated by snippet-bot.
|
Add samples for setting, getting, listing (filter) and deleting GCS object contexts.
Region tags: storage_set_object_contexts, storage_get_object_contexts, storage_list_object_contexts, storage_delete_object_contexts.
storage_set_object_contexts.py: upsert key1/key3 and delete key2 (value=None) with a metageneration-match precondition.storage_get_object_contexts.py: print an object's custom contexts.storage_list_object_contexts.py: list objects usinglist_blobs(filter_=...)with context filters.storage_delete_object_contexts.py: clear all contexts.Requires google-cloud-storage >= 3.11.0 (already pinned at 3.14.1).
Tests:
pytest snippets_test.py -k object_contexts-> 4 passed.Internal bug: b/482946642
[Generated-by: AI]